On Tue, 20 Jan 2026 12:36:54 GMT, Christian Stein <[email protected]> wrote:
> Please review this change to make `jar --validate` check an automatic module
> name given in a manifest file, via the `Automatic-Module-Name` attribute.
>
> Prior to this commit, a `MANFEST.MF` reading
>
> Automatic-Module-Name: default
>
> added into a JAR file named `a.jar` would not fail when passed to `jar
> --validate --file a.jar`. However, it does fail when the JAR file is put on
> the module path of the Java launcher. For example:
>
> $ java --module-path a.jar --describe-module default
>
> Error occurred during initialization of boot layer
> java.lang.module.FindException: Unable to derive module descriptor for a.jar
> Caused by: java.lang.module.FindException: Automatic-Module-Name: default:
> Invalid module name: 'default' is not a Java identifier
>
>
> With this change applied, `jar --validate --file a.jar` will print an error
> message and return a non-zero exit value:
>
>
> invalid module name of Automatic-Module-Name entry in manifest: default
>
>
> The new check also fails for when the module name of a compiled module
> descriptor differs from the value given in the manifest file of the same JAR
> file.
src/jdk.jartool/share/classes/sun/tools/jar/Validator.java line 296:
> 294: } catch (IOException e) {
> 295: errorAndInvalid(e.getMessage());
> 296: }
I feel like this should be put in a separate method rather then be added in
this `if` block. Checking the contents of the manifest feels fundamentally
different from what the other code in this method is doing, namely checking the
consistency of the `EntryInfo` itself.
src/jdk.jartool/share/classes/sun/tools/jar/resources/jar.properties line 144:
> 142: invalid module name of Automatic-Module-Name entry in manifest:
> {0}
> 143: error.validator.manifest.inconsistent.automatic.module.name=\
> 144: expected module name is: {1} - but found Automatic-Module-Name
> entry in manifest: {0}
Would be good here to mention where the expected name is coming from.
Suggestion:
expected module name is: {1} - but found Automatic-Module-Name entry in
manifest: {0}
test/jdk/tools/jar/ValidatorTest.java line 323:
> 321: try {
> 322: jar("--validate --file " + file.toString());
> 323: fail("Expecting non-zero exit code");
Could use `assertThrows`
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/29316#discussion_r2722323625
PR Review Comment: https://git.openjdk.org/jdk/pull/29316#discussion_r2722329155
PR Review Comment: https://git.openjdk.org/jdk/pull/29316#discussion_r2722335182