mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 15:24:43 +02:00
8234423: Modifying ArrayList.subList().subList() resets modCount of subList
Reviewed-by: rriggs
This commit is contained in:
parent
27d782be64
commit
1507a1fb67
2 changed files with 73 additions and 5 deletions
|
@ -1133,7 +1133,7 @@ public class ArrayList<E> extends AbstractList<E>
|
|||
this.parent = parent;
|
||||
this.offset = parent.offset + fromIndex;
|
||||
this.size = toIndex - fromIndex;
|
||||
this.modCount = root.modCount;
|
||||
this.modCount = parent.modCount;
|
||||
}
|
||||
|
||||
public E set(int index, E element) {
|
||||
|
@ -1286,7 +1286,7 @@ public class ArrayList<E> extends AbstractList<E>
|
|||
return new ListIterator<E>() {
|
||||
int cursor = index;
|
||||
int lastRet = -1;
|
||||
int expectedModCount = root.modCount;
|
||||
int expectedModCount = SubList.this.modCount;
|
||||
|
||||
public boolean hasNext() {
|
||||
return cursor != SubList.this.size;
|
||||
|
@ -1330,7 +1330,7 @@ public class ArrayList<E> extends AbstractList<E>
|
|||
final Object[] es = root.elementData;
|
||||
if (offset + i >= es.length)
|
||||
throw new ConcurrentModificationException();
|
||||
for (; i < size && modCount == expectedModCount; i++)
|
||||
for (; i < size && root.modCount == expectedModCount; i++)
|
||||
action.accept(elementAt(es, offset + i));
|
||||
// update once at end to reduce heap write traffic
|
||||
cursor = i;
|
||||
|
@ -1356,7 +1356,7 @@ public class ArrayList<E> extends AbstractList<E>
|
|||
SubList.this.remove(lastRet);
|
||||
cursor = lastRet;
|
||||
lastRet = -1;
|
||||
expectedModCount = root.modCount;
|
||||
expectedModCount = SubList.this.modCount;
|
||||
} catch (IndexOutOfBoundsException ex) {
|
||||
throw new ConcurrentModificationException();
|
||||
}
|
||||
|
@ -1382,7 +1382,7 @@ public class ArrayList<E> extends AbstractList<E>
|
|||
SubList.this.add(i, e);
|
||||
cursor = i + 1;
|
||||
lastRet = -1;
|
||||
expectedModCount = root.modCount;
|
||||
expectedModCount = SubList.this.modCount;
|
||||
} catch (IndexOutOfBoundsException ex) {
|
||||
throw new ConcurrentModificationException();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue