JDK-8279129 : throw StringIndexOutOfBoundsException in com.sun.tools.internal.jxc.ap.Options
  • Type: Enhancement
  • Component: xml
  • Sub-Component: jaxb
  • Affected Version: 8
  • Priority: P4
  • Status: New
  • Resolution: Unresolved
  • OS: generic
  • CPU: generic
  • Submitted: 2021-12-20
  • Updated: 2021-12-22
Description
A DESCRIPTION OF THE PROBLEM :
This method is in tools.jar of jdk1.8.0_301.
This exception can be avoided by replacing args[i].charAt(0) == '-'  with args[i].startsWith("-").
This change can also be seen in the previous commit such as https://github.com/openjdk/jdk/commit/e341e35276315a5140ddec11a7e659d57328e9a0




STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
The unit test case is:
@Test
    public void test_parseArguments() throws com.sun.tools.internal.xjc.BadCommandLineException {
        String[] stringArray1 = {"a ", "^[1]([3-9])[0-9]{9}$", "", ".\\a.txt"};
        com.sun.tools.internal.jxc.ap.Options options0 = new com.sun.tools.internal.jxc.ap.Options();
        options0.parseArguments(stringArray1);
    }

ACTUAL -
java.lang.StringIndexOutOfBoundsException: String index out of range: 0

	at java.lang.String.charAt(String.java:658)
	at com.sun.tools.internal.jxc.ap.Options.parseArguments(Options.java:60)

---------- BEGIN SOURCE ----------
public void parseArguments(String[] args) throws BadCommandLineException {
        for(int i = 0; i < args.length; ++i) {
            if (args[i].charAt(0) == '-') {
                int j = this.parseArgument(args, i);
                if (j == 0) {
                    throw new BadCommandLineException(Messages.UNRECOGNIZED_PARAMETER.format(new Object[]{args[i]}));
                }

                i += j;
            } else {
                this.arguments.add(args[i]);
            }
        }

    }
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
 replace args[i].charAt(0) == '-'  with args[i].startsWith("-")


Comments
The submitter proposed an enhancement of original implementation which avoids throwing StringIndexOutOfBoundsException: String index out of range: 0 Moved to JDK for further evaluations.
22-12-2021