109 |
|
public class ArrayList<E> extends AbstractList<E> |
110 |
|
implements List<E>, RandomAccess, Cloneable, java.io.Serializable |
111 |
|
{ |
112 |
+ |
// OPENJDK @java.io.Serial |
113 |
|
private static final long serialVersionUID = 8683452581122892189L; |
114 |
|
|
115 |
|
/** |
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 |
|
|
857 |
|
* instance is emitted (int), followed by all of its elements |
858 |
|
* (each an {@code Object}) in the proper order. |
859 |
|
*/ |
860 |
+ |
// OPENJDK @java.io.Serial |
861 |
|
private void writeObject(java.io.ObjectOutputStream s) |
862 |
|
throws java.io.IOException { |
863 |
|
// Write out element count, and any hidden stuff |
885 |
|
* could not be found |
886 |
|
* @throws java.io.IOException if an I/O error occurs |
887 |
|
*/ |
888 |
+ |
// OPENJDK @java.io.Serial |
889 |
|
private void readObject(java.io.ObjectInputStream s) |
890 |
|
throws java.io.IOException, ClassNotFoundException { |
891 |
|
|
1140 |
|
this.parent = parent; |
1141 |
|
this.offset = parent.offset + fromIndex; |
1142 |
|
this.size = toIndex - fromIndex; |
1143 |
< |
this.modCount = root.modCount; |
1143 |
> |
this.modCount = parent.modCount; |
1144 |
|
} |
1145 |
|
|
1146 |
|
public E set(int index, E element) { |
1293 |
|
return new ListIterator<E>() { |
1294 |
|
int cursor = index; |
1295 |
|
int lastRet = -1; |
1296 |
< |
int expectedModCount = root.modCount; |
1296 |
> |
int expectedModCount = SubList.this.modCount; |
1297 |
|
|
1298 |
|
public boolean hasNext() { |
1299 |
|
return cursor != SubList.this.size; |
1337 |
|
final Object[] es = root.elementData; |
1338 |
|
if (offset + i >= es.length) |
1339 |
|
throw new ConcurrentModificationException(); |
1340 |
< |
for (; i < size && modCount == expectedModCount; i++) |
1340 |
> |
for (; i < size && root.modCount == expectedModCount; i++) |
1341 |
|
action.accept(elementAt(es, offset + i)); |
1342 |
|
// update once at end to reduce heap write traffic |
1343 |
|
cursor = i; |
1363 |
|
SubList.this.remove(lastRet); |
1364 |
|
cursor = lastRet; |
1365 |
|
lastRet = -1; |
1366 |
< |
expectedModCount = root.modCount; |
1366 |
> |
expectedModCount = SubList.this.modCount; |
1367 |
|
} catch (IndexOutOfBoundsException ex) { |
1368 |
|
throw new ConcurrentModificationException(); |
1369 |
|
} |
1389 |
|
SubList.this.add(i, e); |
1390 |
|
cursor = i + 1; |
1391 |
|
lastRet = -1; |
1392 |
< |
expectedModCount = root.modCount; |
1392 |
> |
expectedModCount = SubList.this.modCount; |
1393 |
|
} catch (IndexOutOfBoundsException ex) { |
1394 |
|
throw new ConcurrentModificationException(); |
1395 |
|
} |