-
Bug
-
Resolution: Fixed
-
P3
-
7
-
None
-
b17
-
generic
-
generic
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-2152539 | OpenJDK6 | Martin Buchholz | P3 | Resolved | Fixed | b01 |
The spec for CopyOnWriteArrayList.subList(...) strongly suggests that
non-structural modifications to parent list (e.g. set(int, Object))
are permitted while a subList is active. In fact, this leads to
ConcurrentModificationException.
* Returns a view of the portion of this list between
* <tt>fromIndex</tt>, inclusive, and <tt>toIndex</tt>, exclusive.
* The returned list is backed by this list, so changes in the
* returned list are reflected in this list, and vice-versa.
* While mutative operations are supported, they are probably not
* very useful for CopyOnWriteArrayLists.
*
* <p>The semantics of the list returned by this method become
* undefined if the backing list (i.e., this list) is
* <i>structurally modified</i> in any way other than via the
* returned list. (Structural modifications are those that change
* the size of the list, or otherwise perturb it in such a fashion
* that iterations in progress may yield incorrect results.)
public class Bug35 {
public static void main(String[] args) throws Throwable {
java.util.List x
= new java.util.concurrent.CopyOnWriteArrayList();
x.add("foo");
java.util.List y = x.subList(0,1);
x.set(0, "bar");
y.get(0);
}
}
=>
Exception in thread "main" java.util.ConcurrentModificationException
at java.util.concurrent.CopyOnWriteArrayList$COWSubList.checkForComodification(CopyOnWriteArrayList.java:1121)
at java.util.concurrent.CopyOnWriteArrayList$COWSubList.get(CopyOnWriteArrayList.java:1150)
at Bug35.main(Bug35.java:8)
non-structural modifications to parent list (e.g. set(int, Object))
are permitted while a subList is active. In fact, this leads to
ConcurrentModificationException.
* Returns a view of the portion of this list between
* <tt>fromIndex</tt>, inclusive, and <tt>toIndex</tt>, exclusive.
* The returned list is backed by this list, so changes in the
* returned list are reflected in this list, and vice-versa.
* While mutative operations are supported, they are probably not
* very useful for CopyOnWriteArrayLists.
*
* <p>The semantics of the list returned by this method become
* undefined if the backing list (i.e., this list) is
* <i>structurally modified</i> in any way other than via the
* returned list. (Structural modifications are those that change
* the size of the list, or otherwise perturb it in such a fashion
* that iterations in progress may yield incorrect results.)
public class Bug35 {
public static void main(String[] args) throws Throwable {
java.util.List x
= new java.util.concurrent.CopyOnWriteArrayList();
x.add("foo");
java.util.List y = x.subList(0,1);
x.set(0, "bar");
y.get(0);
}
}
=>
Exception in thread "main" java.util.ConcurrentModificationException
at java.util.concurrent.CopyOnWriteArrayList$COWSubList.checkForComodification(CopyOnWriteArrayList.java:1121)
at java.util.concurrent.CopyOnWriteArrayList$COWSubList.get(CopyOnWriteArrayList.java:1150)
at Bug35.main(Bug35.java:8)
- backported by
-
JDK-2152539 CopyOnWriteArrayList subLists prohibit even non-structural modifications to parent list
-
- Resolved
-