mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 23:04:50 +02:00
8222930: ConcurrentSkipListMap.clone() shares size variable between original and clone
Co-authored-by: Martin Buchholz <martinrb@google.com> Reviewed-by: martin, smarks
This commit is contained in:
parent
7d4520c109
commit
d97dd4d554
2 changed files with 27 additions and 0 deletions
|
@ -1129,6 +1129,7 @@ public class ConcurrentSkipListMap<K,V> extends AbstractMap<K,V>
|
||||||
clone.entrySet = null;
|
clone.entrySet = null;
|
||||||
clone.values = null;
|
clone.values = null;
|
||||||
clone.descendingMap = null;
|
clone.descendingMap = null;
|
||||||
|
clone.adder = null;
|
||||||
clone.buildFromSorted(this);
|
clone.buildFromSorted(this);
|
||||||
return clone;
|
return clone;
|
||||||
} catch (CloneNotSupportedException e) {
|
} catch (CloneNotSupportedException e) {
|
||||||
|
|
|
@ -200,6 +200,32 @@ public class MapTest extends JSR166TestCase {
|
||||||
assertEquals(size1 + size2, m1.size());
|
assertEquals(size1 + size2, m1.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 8222930: ConcurrentSkipListMap.clone() shares size variable between original and clone
|
||||||
|
*/
|
||||||
|
public void testClone() {
|
||||||
|
final ThreadLocalRandom rnd = ThreadLocalRandom.current();
|
||||||
|
final int size = rnd.nextInt(4);
|
||||||
|
final Map map = impl.emptyMap();
|
||||||
|
for (int i = 0; i < size; i++)
|
||||||
|
map.put(impl.makeKey(i), impl.makeValue(i));
|
||||||
|
final Map clone = cloneableClone(map);
|
||||||
|
if (clone == null) return; // not cloneable?
|
||||||
|
|
||||||
|
assertEquals(size, map.size());
|
||||||
|
assertEquals(size, clone.size());
|
||||||
|
assertEquals(map.isEmpty(), clone.isEmpty());
|
||||||
|
|
||||||
|
clone.put(impl.makeKey(-1), impl.makeValue(-1));
|
||||||
|
assertEquals(size, map.size());
|
||||||
|
assertEquals(size + 1, clone.size());
|
||||||
|
|
||||||
|
clone.clear();
|
||||||
|
assertEquals(size, map.size());
|
||||||
|
assertEquals(0, clone.size());
|
||||||
|
assertTrue(clone.isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
// public void testFailsIntentionallyForDebugging() {
|
// public void testFailsIntentionallyForDebugging() {
|
||||||
// fail(impl.klazz().getSimpleName());
|
// fail(impl.klazz().getSimpleName());
|
||||||
// }
|
// }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue