Note bulk methods in Javadocs for Collections.synchronizedXxx()

Roman Leventov leventov.ru at gmail.com
Sat Dec 28 09:50:10 UTC 2019


I think Javadocs for Collections.synchronizedXxx() should mention not
only "traversing it via Iterator, Spliterator or Stream" as something that
must be synchronized externally, but also cases when a synchronized
collection is an argument to a bulk collection method, including:
 - new ArrayList(syncList), new HashSet(syncSet),  etc.
 - List.copyOf(syncList)
 - otherColl.addAll(syncList), otherColl.removeAll(syncList),
otherMap.putAll(syncMap).

Though this is logically inferable, this is far from being obvious and
apparent.


More information about the core-libs-dev mailing list