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

(coll) ArrayList(Collection) fails for concurrent modified collections

    XMLWordPrintable

Details

    • Enhancement
    • Status: Closed
    • P4
    • Resolution: Duplicate
    • 5.0
    • None
    • core-libs

    Description

      A DESCRIPTION OF THE REQUEST :
      If a collection passed to ArrayList(Collection) is modified during the execution of the constructor the resulting List contains null-elements instead of the collection's elements.

      The problem lies here:

              elementData = (E[])new Object[...];
              c.toArray(elementData);

      It is thought, c.toArray(elementData) puts the elements to the passed array in all cases, but if the array is too small, another one is returned.

      Changing the code to

              elementData = (E[])new Object[...];
              elementData = c.toArray(elementData);

      fixes the problem.

      JUSTIFICATION :
      The comment of the constructor says "Constructs a list containing the elements of the specified collection[...]" but returns a list containing NO element of the collection (if the collection does not contain null).

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The elements in ArrayList after call of ArrayList(c) are equal to the elements of collection c at a time t with Construction_start <= t <= Construction_end
      ACTUAL -
      ArrayList with null-Elements for collections modified while construction.

      Attachments

        Issue Links

          Activity

            People

              martin Martin Buchholz
              ndcosta Nelson Dcosta (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: