On Mon, 22 Jan 2024 06:50:21 GMT, Tejesh R <t...@openjdk.org> wrote: >> src/java.desktop/share/classes/javax/swing/plaf/basic/BasicDirectoryModel.java >> line 417: >> >>> 415: } >>> 416: >>> 417: private synchronized <T> boolean compareIterators(Iterator<T> >>> iterator1, Iterator<T> iterator2) { >> >> I'm not sure I understand, how this `synchronized` helps to avoid the issue. > > Since concurrent modification exception is thrown, it is clear that the List > is being modified while comparing two list. Hence instead of copying the list > locally, I have used iterators and comparing element by element in a > `synchronized` method which ensures single thread is accessing the iterators. > Without `synchronized` I guess it would again cause > `concurrentModificationException`.
Vector.iterator and Vector.subList.iterator are still check for modification on iteration (see usages of the method `java.util.AbstractList.SubList#checkForComodification`). It means, if vector was concurrently modified during iteration - iteration will fail with the `ConcurrentModificationException` ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/17462#discussion_r1461427786