Uploaded image for project: 'Derby'
  1. Derby
  2. DERBY-2265

bad logic in jvm:guessWSHome() in old test harness affects j9 runs

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 10.3.1.4
    • 10.3.1.4
    • Test
    • None
    • wctme5.7_foundation (j2ME 1.0) or weme6.1 (foundation, j2ME 1.1)
    • Normal

    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)

      { wshome = jhome.substring(0,jhome.indexOf(sep + "jre")); wshome = wshome.substring(0,wshome.lastIndexOf(sep)); }

      else
      wshome = jhome.substring(0,jhome.lastIndexOf(sep));

      Attachments

        1. DERBY-2265_20070123.diff
          1.0 kB
          Myrna van Lunteren

        Activity

          People

            myrna Myrna van Lunteren
            myrna Myrna van Lunteren
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: