-
Type:
Bug
-
Resolution: Fixed
-
Priority:
P4
-
Affects Version/s: 17, 20, 21
-
Component/s: core-libs
Created for https://github.com/openjdk/jdk/pull/11679
NavigableMap m = Collections.synchronizedNavigableMap(new TreeMap());
NavigableMap m2 = m.subMap(foo, true, bar, false);
...
Set s2 = m2.keySet(); // Needn't be in synchronized block
...
synchronized (m) { // Synchronizing on m, not m2 or s2!
Iterator i = s.iterator(); // Must be in synchronized block
while (i.hasNext())
foo(i.next());
}
Should be
Iterator i = s2.iterator();
NavigableMap m = Collections.synchronizedNavigableMap(new TreeMap());
NavigableMap m2 = m.subMap(foo, true, bar, false);
...
Set s2 = m2.keySet(); // Needn't be in synchronized block
...
synchronized (m) { // Synchronizing on m, not m2 or s2!
Iterator i = s.iterator(); // Must be in synchronized block
while (i.hasNext())
foo(i.next());
}
Should be
Iterator i = s2.iterator();