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

Arrays.copyOfRange method throws OutOfMemoryError

XMLWordPrintable

      ADDITIONAL SYSTEM INFORMATION :
      Picked up _JAVA_OPTIONS: -Dawt.useSystemAAFontSettings=gasp
      java version "1.8.0_151"
      Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
      Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)

      A DESCRIPTION OF THE PROBLEM :
      Arrays.copyOfRange specification defines that a NullPointerException should be throw if original parameter is null (https://docs.oracle.com/javase/8/docs/api/java/util/Arrays.html#copyOfRange-byte:A-int-int-). However, it throws OutOfMemoryError when executing the following program:

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Compile above program
      2. Run it using Oracle HotSpot java

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      NullPointerException.
      ACTUAL -
      Exception in thread "main" java.lang.OutOfMemoryError: Requested array size exceeds VM limit
      at java.util.Arrays.copyOfRange(Arrays.java:3520)
      at A.main(A.java:4)

      ---------- BEGIN SOURCE ----------
      import java.util.Arrays;
      public class A {
         public static void main(String args[]) {
            Arrays.copyOfRange((byte[])null, 0, 2147483647);
         }
      }
      ---------- END SOURCE ----------

      FREQUENCY : always


            psonal Pallavi Sonal (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: