JDK-8169713 : jimage fails with StringIndexOutOfBoundsException when path to the inspected image is an empty string
  • Type: Bug
  • Component: tools
  • Sub-Component: jlink
  • Affected Version: 9
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2016-11-15
  • Updated: 2017-03-13
  • Resolved: 2017-02-23
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 10 JDK 9
10Fixed 9 b159Fixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Description
The following command causes a failure:

% jimage list ''

java.lang.StringIndexOutOfBoundsException: String index out of range: 0
        at java.base/java.lang.StringLatin1.charAt(StringLatin1.java:45)
        at java.base/java.lang.String.charAt(String.java:704)
        at jdk.jlink/jdk.tools.jlink.internal.TaskHelper$OptionsHelper.handleOptions(TaskHelper.java:530)
        at jdk.jlink/jdk.tools.jlink.internal.TaskHelper$OptionsHelper.handleOptions(TaskHelper.java:482)
        at jdk.jlink/jdk.tools.jimage.JImageTask.run(JImageTask.java:174)
        at jdk.jlink/jdk.tools.jimage.Main.main(Main.java:34)


If the last argument is omitted the correct message appears:
% jimage list
Error: no jimage provided

The issue affects all jimage commands: info, list, extract, verify.

Tested on the latest jigsaw and jdk 9-ea+144.
Comments
Fix does not appear to have been applied correctly
23-02-2017

Jim, as you proposed the fix I'm reassigning this bug to you.
19-12-2016

It has been already done. Also I listed all these issues in JDK-8170120.
25-11-2016

Please file jlink/jimage bugs for tests that failed. We may not get fixes in before the deadline but at least we are tracking them.
24-11-2016

diff -r 1b2298dd1c08 src/jdk.jlink/share/classes/jdk/tools/jlink/internal/TaskHelper.java --- a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/TaskHelper.java Mon Nov 21 10:08:20 2016 -0400 +++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/TaskHelper.java Mon Nov 21 11:45:15 2016 -0400 @@ -563,7 +563,7 @@ List<String> rest = collectUnhandled? new ArrayList<>() : null; // process options for (int i = 0; i < args.length; i++) { - if (args[i].charAt(0) == '-') { + if (args[i].startsWith("-")) { String name = args[i]; PluginOption pluginOption = null; Option<T> option = getOption(name);
21-11-2016