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

XMLWordPrintable

    • Type: Enhancement
    • Resolution: Duplicate
    • Priority: P4
    • None
    • Affects Version/s: 5.0
    • Component/s: core-libs

      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.

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: