Hi, The Jar File Specification [1] states that,
> If the last character of the file is an EOF character (code 26), the EOF is treated as whitespace. Two newlines are appended (one for editors that don't put a newline at the end of the last line, and one so that the grammar doesn't have to special-case the last entry, which may not have a blank line after it). But I can't see that this is actually the case. See the attached simple test that indicates that this statement is not implemented. See also potentially remotely related bugs [2] and [3] which both refer in my opinion to EOF as the end of the byte stream as opposed to the EOF character 26. After nobody has fixed this point inside of many years I tend to assume that it is not at all necessary or useful. However, I cannot understand the intention behind it or how that statement got there in the first place and hence might not be aware of the full context. Considering the activity about the last line of a manifest not terminated by a line break resulting in that line ignored unexpectedly (see [3] through [14]) I doubt that it is promising to attempt to implement the EOF according to the specs. Instead I'd rather like to propose to update the specification by removing the quoted statement. I'm not sure if the specification [1] has changed since 13 or where the most up to date one is. Regards, Philipp [1] https://docs.oracle.com/en/java/javase/13/docs/specs/jar/jar.html#notes-on-manifest-and-signature-files EOF-related: [2] https://bugs.openjdk.java.net/browse/JDK-7148584 [3] https://bugs.openjdk.java.net/browse/JDK-4639129 Last line break required or missing related: [4] https://bugs.openjdk.java.net/browse/JDK-4274235 [5] https://bugs.openjdk.java.net/browse/JDK-4894998 [6] https://bugs.openjdk.java.net/browse/JDK-4333854 [7] https://bugs.openjdk.java.net/browse/JDK-6594305 [8] http://mail.openjdk.java.net/pipermail/core-libs-dev/2019-February/058774.html [9] https://bugs.openjdk.java.net/browse/JDK-4489716 [10] https://bugs.openjdk.java.net/browse/JDK-4639129 [11] https://bugs.openjdk.java.net/browse/JDK-4625822 [12] https://stackoverflow.com/questions/21859417/header-must-be-terminated-by-a-line-break-eclipse-manifest-mf [13] https://bugs.eclipse.org/bugs/show_bug.cgi?id=377249 [14] https://bugs.java.com/bugdatabase/view_bug.do?bug_id=4274235
diff -r d6058bd73982 test/jdk/java/util/jar/Manifest/EOF.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/jdk/java/util/jar/Manifest/EOF.java Fri Oct 11 08:10:37 2019 +0200 @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import static java.nio.charset.StandardCharsets.UTF_8; + +import java.io.ByteArrayInputStream; +import java.util.jar.Attributes.Name; +import java.util.jar.Manifest; + +import org.testng.annotations.Test; +import static org.testng.Assert.*; + +/** + * @test + * @run testng EOF + * @summary Tests parsing a manifest with an EOF character (code 26) at its end. + */ +public class EOF { + + @Test + public void test() throws Exception { + byte[] mfBytes = (Name.MANIFEST_VERSION + ": 1.0\r\n" + + "Key: Value\u001a").getBytes(UTF_8); + Manifest mf = new Manifest(new ByteArrayInputStream(mfBytes)); + assertEquals(mf.getMainAttributes().getValue("Key"), "Value"); + } + +}