Details
Description
Running derbyall using either wcmte5.7_foundation or weme6.1 results in the following stack trace.
Exception in thread "main" java.lang.StringIndexOutOfBoundsException
at java.lang.String.substring(String.java:1043)
at org.apache.derbyTesting.functionTests.harness.jvm.guessWSHome(jvm.java:301)
at org.apache.derbyTesting.functionTests.harness.jvm.getSecurityProps(jvm.java:356)
at org.apache.derbyTesting.functionTests.harness.jvm.setSecurityProps(jvm.java:336)
at org.apache.derbyTesting.functionTests.harness.RunTest.buildTestCommand(RunTest.java:2350)
at org.apache.derbyTesting.functionTests.harness.RunTest.testRun(RunTest.java:498)
at org.apache.derbyTesting.functionTests.harness.RunTest.main(RunTest.java:368)
I think this code was not reached until various security related changes recently, but the code is just bad.
I think this code was used at one point to attempt to kick off another jvm to run a server with, but that is now defunct.
Rather than try to make the code work, or try to clean it up, I'd rather spend time converting tests to the junit framework, so I will just fix this up so we don't hit the error.
The bad code is:
wshome = jhome.substring(0,jhome.indexOf(sep + "jre"));
wshome = wshome.substring(0,wshome.lastIndexOf(sep));
If the jhome ( System.getProperty("java.home")) does not contain 'jre', we will get -1 as the 2nd parameter in jhome.substring, and thus cause the ArrayIndexOutOfBounds.
I propose to fix this piece of code as follows:
int havejre=jhome.indexOf(sep + "jre");
if (havejre > 0)
else
wshome = jhome.substring(0,jhome.lastIndexOf(sep));