[concurrency-interest] ConcurrentHashMap entrySet Iterator remove issue?

Martin Buchholz martinrb at google.com
Fri Feb 5 21:05:12 EST 2016

It's not entirely clear whether entrySet().iterator().remove() should
remove the entry for the current key or only if still mapped to the
old value.  But acting like the latter seems better for users - I
agree with Mike.  The existence of map.remove(K, V) gives an
expectation that iterator().remove() works likewise.

The counter-arguments against switching now are:
- it is a small added implementation burden for the iterator to keep
track of the old value, that will almost never be used.
- users can just call remove(K, V) - they have the old v in hand, that
the map has already forgotten.
- status quo wins whenever there's doubt!

But the behavior should be documented.

More information about the Concurrency-interest mailing list