RFR: 8204256: improve jlink error message to report unsupported class file format [v3]

Alan Bateman alanb at openjdk.java.net
Tue Oct 6 06:10:45 UTC 2020


On Mon, 5 Oct 2020 18:57:52 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 updated the pull request incrementally with one additional commit since the last revision:
> 
>   Fixing formatting

src/jdk.jlink/share/classes/jdk/tools/jlink/internal/JlinkTask.java line 280:

> 278:         } catch (FindException e) {
> 279:             log.println(taskHelper.getMessage("err.prefix") + " " + e.getMessage());
> 280:             e.printStackTrace(log);

I think my preference would be to not print the stack trace here, instead print the exception and the cause. This is to
avoid users of the tool thinking that the tool "has crashed".

-------------

PR: https://git.openjdk.java.net/jdk/pull/409


More information about the core-libs-dev mailing list