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

clean up defensive code from ArrayList, MOAT test

    Details

    • Type: Enhancement
    • Status: Open
    • Priority: P5
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:

      Description

      The ArrayList(Collection) constructor contains the following code:

                  // defend against c.toArray (incorrectly) not returning Object[]
                  // (see e.g. https://bugs.openjdk.java.net/browse/JDK-6260652)
                  if (elementData.getClass() != Object[].class)
                      elementData = Arrays.copyOf(elementData, size, Object[].class);

      This is present because Arrays.asList().toArray() used to return an array with the wrong component type. This was fixed by JDK-6260652.

      The test MOAT.java has test cases that ensure that toArray() always returns Object[], with extra code to work around the Arrays.asList().toArray() bug. This extra code can be removed as well. (Search for the string "6260652" in MOAT.java.)

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              smarks Stuart Marks
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: