-
Bug
-
Resolution: Fixed
-
P3
-
6
-
b61
-
generic
-
generic
We want to improve the behavior of
CopyOnWriteArraySet.equals()
CopyOnWriteArrayList.equals()
in the presence of concurrent modification of "this" or the other collection
(if it is also a concurrent collection).
Currently it is possible for x.equals(y) to spuriously return true even if
no snapshots of x and y are ever equal, and it is also possible for this to
throw NoSuchElementException, in the presence of concurrent modification.
The whole point of the "COW" classes is to provide reasonable, safe behavior
in the presence of concurrent modification.
Users expect methods of CopyOnWriteArraySet to operate on snapshots at the point of call.
This means that COWAS methods should not call size(), and only then access its
internal array. However, the implementation of equals(Object), inherited from
AbstractSet does precisely that.
As a result, we lose the desirable property that if s1 and s2 are both
CopyOnWriteArraySets, then s1.equals(s2) can only be true if a snapshot
of s1 contains the same elements as a snapshot of s2.
Similarly, we would like the same desirable property for CopyOnWriteArrayLists:
l1.equals(l2) can only be true if a snapshot
of s1 contains the same elements as a snapshot of s2.
The implementation needs to be careful to take into account concurrent modification
of both this collection and the other. In the case of the other collection,
this is more difficult because we don't know what the implementation might be.
CopyOnWriteArraySet.equals()
CopyOnWriteArrayList.equals()
in the presence of concurrent modification of "this" or the other collection
(if it is also a concurrent collection).
Currently it is possible for x.equals(y) to spuriously return true even if
no snapshots of x and y are ever equal, and it is also possible for this to
throw NoSuchElementException, in the presence of concurrent modification.
The whole point of the "COW" classes is to provide reasonable, safe behavior
in the presence of concurrent modification.
Users expect methods of CopyOnWriteArraySet to operate on snapshots at the point of call.
This means that COWAS methods should not call size(), and only then access its
internal array. However, the implementation of equals(Object), inherited from
AbstractSet does precisely that.
As a result, we lose the desirable property that if s1 and s2 are both
CopyOnWriteArraySets, then s1.equals(s2) can only be true if a snapshot
of s1 contains the same elements as a snapshot of s2.
Similarly, we would like the same desirable property for CopyOnWriteArrayLists:
l1.equals(l2) can only be true if a snapshot
of s1 contains the same elements as a snapshot of s2.
The implementation needs to be careful to take into account concurrent modification
of both this collection and the other. In the case of the other collection,
this is more difficult because we don't know what the implementation might be.