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

new ArrayList(largeList) throws NegativeArraySizeException

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.4.0
    • 1.3.0
    • core-libs
    • beta
    • generic
    • generic
    • Verified



      Name: jb33418 Date: 09/29/2000


      java version "1.3.0beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0beta-b07)
      Java HotSpot(TM) Client VM (build 1.3.0beta-b04, mixed mode)

      When constructing an ArrayList from an existing List,
      the constructor fails if the list has 19522579 or more
      elements. This can be tested simply using the following:



      import java.util.*;

      public class ListTest {
          public static void main(String[] args) throws Exception {
      if (args.length < 1)
      throw new Exception("usage: test.ListTest <count>");

      int count = Integer.parseInt(args[0]);

      String myObject = "Hello, world";
      List myList = Collections.nCopies(count, myObject);
      List myList2 = new ArrayList(myList);
          }
      }


      The command line:
        java -Xmx300M ListTest 19522578
      succeeds, but:
        java -Xmx300M ListTest 19522579
      fails with:

      Exception in thread "main" java.lang.NegativeArraySizeException
              at java.util.ArrayList.<init>(ArrayList.java:120)
              at test.ListTest.main(ListTest.java:16)

      NB. Exact heap size is not important, so long as it is large enough
      to construct the list.

        To date, I have seen this problem in the Sun 1.3beta release
      for Linux, and also in the Compaq 1.2.2-3 release for Tru64
      Unix. I believe that this is a general problem in the class
      libraries.
      (Review ID: 106783)
      ======================================================================

            jjb Josh Bloch (Inactive)
            jjb Josh Bloch (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: