8340572: ConcurrentModificationException when sorting ArrayList sublists

Reviewed-by: smarks
This commit is contained in:
Attila Szegedi 2024-10-05 21:15:18 +00:00
parent 9a25f822fb
commit 260d4658ae
2 changed files with 60 additions and 1 deletions

View file

@ -1808,6 +1808,7 @@ public class ArrayList<E> extends AbstractList<E>
@Override
public void sort(Comparator<? super E> c) {
sortRange(c, 0, size);
modCount++;
}
@SuppressWarnings("unchecked")
@ -1816,7 +1817,6 @@ public class ArrayList<E> extends AbstractList<E>
Arrays.sort((E[]) elementData, fromIndex, toIndex, c);
if (modCount != expectedModCount)
throw new ConcurrentModificationException();
modCount++;
}
void checkInvariants() {