< prev index next >
test/jdk/java/util/concurrent/tck/ConcurrentHashMapTest.java
Print this page
8211283: Miscellaneous changes imported from jsr166 CVS 2018-11
Reviewed-by: martin, chegar
*** 863,868 ****
--- 863,884 ----
for (int i = 0; i < iterations; i++)
assertFalse(keySet.removeAll(removeMe));
assertEquals(mapSize, map.size());
}
+ public void testReentrantComputeIfAbsent() {
+ ConcurrentHashMap<Integer, Integer> map = new ConcurrentHashMap<>(16);
+ try {
+ for (int i = 0; i < 100; i++) { // force a resize
+ map.computeIfAbsent(i, key -> findValue(map, key));
+ }
+ fail("recursive computeIfAbsent should throw IllegalStateException");
+ } catch (IllegalStateException success) {}
+ }
+
+ private Integer findValue(ConcurrentHashMap<Integer, Integer> map,
+ Integer key) {
+ return (key % 5 == 0) ? key :
+ map.computeIfAbsent(key + 1, k -> findValue(map, k));
+ }
+
}
< prev index next >