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

(cs) String(byte[]) constructor does not work on enormous byte arrays

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.4.2, 5.0
    • core-libs
    • x86
    • linux, windows_2000



      Name: rmT116609 Date: 11/05/2003


      FULL PRODUCT VERSION :
      java version "1.4.2"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-b28)
      Java HotSpot(TM) Client VM (build 1.4.2-b28, mixed mode)

      FULL OS VERSION :
      Microsoft Windows 2000 [Version 5.00.2195]

      A DESCRIPTION OF THE PROBLEM :
      String Constructor public String(byte[] bytes) produces a BufferOverflowEception in nio package when passing a large array of a certain size

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create a new String object passing an byte array of size 28664105.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The bug is reproducible for array sizes incremented by 4 (e.g. 28664105, 28664109, 28664113,...) It works fine for values between (e.g. 28664106, 28664107, 28664108).
      ACTUAL -
      The constructor throws a BufferoverflowException

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      java.nio.BufferOverflowException
      at java.nio.charset.CoderResult.throwException(Unknown Source)
      at java.lang.StringCoding$CharsetSD.decode(Unknown Source)
      at java.lang.StringCoding.decode(Unknown Source)
      at java.lang.StringCoding.decode(Unknown Source)
      at java.lang.String.<init>(Unknown Source)
      at java.lang.String.<init>(Unknown Source)
      at TestBufferOverflow.main(TestBufferOverflow.java:18)
      Exception in thread "main"

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class TestBufferOverflow {
      public static void main(String[] args) {
      int maxNumber = 28664105;
      byte[] ByteArray = new byte[maxNumber];
      String newStr = new String (ByteArray);
      }
      }

      ---------- END SOURCE ----------
      (Incident Review ID: 198982)
      ======================================================================

            martin Martin Buchholz
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: