ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/ArrayList.java
(Generate patch)

Comparing jsr166/src/main/java/util/ArrayList.java (file contents):
Revision 1.70 by jsr166, Fri Jan 10 21:32:08 2020 UTC vs.
Revision 1.71 by jsr166, Fri Jul 24 20:57:26 2020 UTC

# Line 178 | Line 178 | public class ArrayList<E> extends Abstra
178       * @throws NullPointerException if the specified collection is null
179       */
180      public ArrayList(Collection<? extends E> c) {
181 <        elementData = c.toArray();
182 <        if ((size = elementData.length) != 0) {
183 <            // defend against c.toArray (incorrectly) not returning Object[]
184 <            // (see e.g. https://bugs.openjdk.java.net/browse/JDK-6260652)
185 <            if (elementData.getClass() != Object[].class)
186 <                elementData = Arrays.copyOf(elementData, size, Object[].class);
181 >        Object[] a = c.toArray();
182 >        if ((size = a.length) != 0) {
183 >            if (c.getClass() == ArrayList.class) {
184 >                elementData = a;
185 >            } else {
186 >                elementData = Arrays.copyOf(a, size, Object[].class);
187 >            }
188          } else {
189              // replace with empty array.
190 <            this.elementData = EMPTY_ELEMENTDATA;
190 >            elementData = EMPTY_ELEMENTDATA;
191          }
192      }
193  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines