RFR: 8204256: improve jlink error message to report unsupported class file format [v2]
Mandy Chung
mchung at openjdk.java.net
Thu Oct 1 22:49:03 UTC 2020
On Thu, 1 Oct 2020 19:19:18 GMT, Ian Graves <igraves at openjdk.org> wrote:
>> This pull request contains a change to facilitate better error messages in jlink for when jlink creates an image from
>> jmod files that are unsupported by the runtime by being _too new_. The existing behavior supports modules that are too
>> old via an error about a mismatched version. The solution to this problem is constrained by jlink's use of some
>> specified behavior by java.lang.module.ModuleFinder. The solution in this PR is to subclass some existing exceptions
>> internally as to signal to jlink more specific error conditions when attempting to find and open modules. Bug here:
>> https://bugs.openjdk.java.net/browse/JDK-8204256
>> New Error message example:
>>
>> reading module: /Users/igraves/dev/jdk-otro/build/macosx-x64/images/jmods/java.security.sasl.jmod
>> java.lang.module.FindException: Error reading module:
>> /Users/igraves/dev/jdk-otro/build/macosx-x64/images/jmods/java.security.sasl.jmod at
>> java.base/jdk.internal.module.ModulePath.readModule(ModulePath.java:350) at
>> java.base/jdk.internal.module.ModulePath.scanDirectory(ModulePath.java:284) at
>> java.base/jdk.internal.module.ModulePath.scan(ModulePath.java:232) at
>> java.base/jdk.internal.module.ModulePath.scanNextEntry(ModulePath.java:190) at
>> java.base/jdk.internal.module.ModulePath.find(ModulePath.java:154) at
>> jdk.jlink/jdk.tools.jlink.internal.JlinkTask.newModuleFinder(JlinkTask.java:443) at
>> jdk.jlink/jdk.tools.jlink.internal.JlinkTask.initJlinkConfig(JlinkTask.java:374) at
>> jdk.jlink/jdk.tools.jlink.internal.JlinkTask.run(JlinkTask.java:267) at
>> jdk.jlink/jdk.tools.jlink.internal.Main.run(Main.java:54) at jdk.jlink/jdk.tools.jlink.internal.Main.main(Main.java:33)
>> Caused by: java.lang.module.InvalidModuleDescriptorException: Unsupported major.minor version 60.0
>> at java.base/jdk.internal.module.ModuleInfo.invalidModuleDescriptor(ModuleInfo.java:1088)
>> at java.base/jdk.internal.module.ModuleInfo.doRead(ModuleInfo.java:192)
>> at java.base/jdk.internal.module.ModuleInfo.read(ModuleInfo.java:129)
>> at java.base/jdk.internal.module.ModulePath.readJMod(ModulePath.java:395)
>> at java.base/jdk.internal.module.ModulePath.readModule(ModulePath.java:343)
>> ... 9 more```
>
> Ian Graves has refreshed the contents of this pull request, and previous commits have been removed. The incremental
> views will show differences compared to the previous content of the PR.
Given that linking with JMODs of an unsupported class file version is rare case,
it's not a bad choice to go with this simplest solution printing the stack trace.
src/jdk.jlink/share/classes/jdk/tools/jlink/internal/JlinkTask.java line 232:
> 230: if (remaining.size() > 0 && !options.suggestProviders) {
> 231: throw taskHelper.newBadArgs("err.orphan.arguments",
> 232: remaining.stream().collect(Collectors.joining(" ")))
Formatting nit: this change makes it a little hard to see it's an argument passed to `newBadArgs`.
-------------
Marked as reviewed by mchung (Reviewer).
PR: https://git.openjdk.java.net/jdk/pull/409
More information about the core-libs-dev
mailing list