Uploaded image for project: 'Harmony'
  1. Harmony
  2. HARMONY-2144

[drlvm][jit][opt] ABCD causes unexpected NullPointerException instead of ArrayIndexOutOfBoundsException

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 5.0M10
    • DRLVM
    • None
    • Any

    Description

      ABCD causes unexpected NullPointerException instead of ArrayIndexOutOfBoundsException.

      Consider that index of array element called inside a loop depends on the loop control variable.
      An overflow occurs on some loop iteration and corrupts the value of loop control variable so that it became negative.
      An array tries to be accessed with an illegal negative index.
      ArrayIndexOutOfBoundsException should be thrown in this case, but if abcd pass is turned on it causes unexpected NullPointerException.

      Please, see the code example below.

      Code for reproducing:

      public class abcdTest2 {

      private final int limit = 10000;

      public static void main(String[] args)

      { System.exit(new abcdTest2().test()); }

      public int test() {
      System.out.println("Start abcdTest2 ...");
      int arr[] = new int[limit];
      int j=1;
      try {
      for(int k=2; k<limit; k=1+k+k*j)

      { if (k<0) System.out.println("---Overflow---"); System.out.println("k=" + k + ": arr[" + (k-2) + "] will be called"); arr[k] = arr[k-2]; j = k*k; }

      } catch (ArrayIndexOutOfBoundsException e)

      { System.out.println("TEST PASSED ArrayIndexOutOfBoundsException was thrown"); return 0; }

      catch (Exception e)

      { e.printStackTrace(); System.out.println("TEST FAILED: unexpected exeption was thrown"); return 1; }

      System.out.println("TEST FAILED: ArrayIndexOutOfBoundsException wasn't thrown");
      return 1;
      }
      }

      Steps to Reproduce:
      Compile abcdTest2 class and run it on Harmony with '-Xem:server_static' option.

      Output on Windows:

      Apache Harmony Launcher : (c) Copyright 1991, 2006 The Apache Software Foundation or its licensors,
      as applicable.
      java version "1.5.0"
      pre-alpha : not complete or compatible
      svn = r473012, (Nov 10 2006), Windows/ia32/msvc 1310, release build
      http://incubator.apache.org/harmony
      Start abcdTest2 ...
      k=2: arr[0] will be called
      k=11: arr[9] will be called
      k=1343: arr[1341] will be called
      --Overflow--
      k=-1872665345: arr[-1872665347] will be called
      java.lang.NullPointerException
      at abcdTest2.test(abcdTest2.java)
      at abcdTest2.main(abcdTest2.java:6)
      TEST FAILED: unexpected exception was thrown

      Output on Linux:

      x_ia32_0002_icc_r_H/bin/java -showversion -Xem:server_static abcdTest2
      Apache Harmony Launcher : (c) Copyright 1991, 2006 The Apache Software Foundation or its licensors, as applicable.
      java version "1.5.0"
      pre-alpha : not complete or compatible
      svn = r473012, (Nov 10 2006), Linux/ia32/icc 900, release build
      http://incubator.apache.org/harmony
      Start abcdTest2 ...
      k=2: arr[0] will be called
      k=11: arr[9] will be called
      k=1343: arr[1341] will be called
      --Overflow--
      k=-1872665345: arr[-1872665347] will be called
      java.lang.NullPointerException
      at abcdTest2.test(abcdTest2.java)
      at abcdTest2.main(abcdTest2.java:6)
      TEST FAILED: unexpected exception was thrown

      Output on RI:
      Start abcdTest2 ...
      k=2: arr[0] will be called
      k=11: arr[9] will be called
      k=1343: arr[1341] will be called
      --Overflow--
      k=-1872665345: arr[-1872665347] will be called
      TEST PASSED ArrayIndexOutOfBoundsException was thrown

      Attachments

        1. abcdTest2.java
          0.9 kB
          Elena Sayapina

        Activity

          People

            Unassigned Unassigned
            evs Elena Sayapina
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: