Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6588260

(str) ArrayIndexOutOfBoundsException when trying to create a String from codePoints

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 6
    • Fix Version/s: 7
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b19
    • CPU:
      x86
    • OS:
      linux
    • Verification:
      Not verified

      Description

      FULL PRODUCT VERSION :
      java -version
      java version "1.6.0"
      Java(TM) SE Runtime Environment (build 1.6.0-b105)
      Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)

      java version "1.5.0_11"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_11-b03)
      Java HotSpot(TM) Client VM (build 1.5.0_11-b03, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Linux edwin-t-new 2.6.22.1-cfs-v19 #1 SMP PREEMPT Tue Jul 17 12:46:51 EEST 2007 i686 GNU/Linux


      A DESCRIPTION OF THE PROBLEM :
      When trying to create a string containing all codePoints (in range Character.MIN_CODE_POINT, Character.MAX_CODE_POINT) an ArrayIndexOutOfBounds exception is thrown from the String constructor.

      Occurs with both java 1.5, and java 1.6.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile the sample code below: javac Test.java
      Run the sample code: java Test


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      No exceptions are thrown
      ACTUAL -
      Exception is thrown in the String constructor.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      When running with JDK 1.6.0:
      Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1114113
              at java.lang.Character.toSurrogates(Character.java:2596)
              at java.lang.String.<init>(String.java:286)
              at Test.main(Test.java:7)

      When running with JDK 1.5.0.11:
      Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1114113
              at java.lang.Character.toSurrogates(Character.java:2596)
              at java.lang.String.<init>(String.java:275)
              at Test.main(Test.java:7)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      class Test {
      public static void main(String[] args) {
              int [] codePoints=new int[Character.MAX_CODE_POINT];
              for(int i=0;i<codePoints.length;i++) {
                  codePoints[i] = i;
              }
              final String original = new String(codePoints, 0, codePoints.length);

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

        Activity

        Hide
        martin Martin Buchholz added a comment -
        BT2:EVALUATION

        The constructor String(int[], int, int) has a complex and buggy implementation.
        Also, it does not guard against having the String backing array have
        trailing never-accessed chars.

        A more obvious implementation will be more clearly correct and clearly
        time- and space-efficient.
        Show
        martin Martin Buchholz added a comment - BT2:EVALUATION The constructor String(int[], int, int) has a complex and buggy implementation. Also, it does not guard against having the String backing array have trailing never-accessed chars. A more obvious implementation will be more clearly correct and clearly time- and space-efficient.

          People

          • Assignee:
            martin Martin Buchholz
            Reporter:
            ryeung Roger Yeung (Inactive)
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:
              Imported:
              Indexed: