--- jsr166/src/test/tck/ConcurrentHashMapTest.java 2018/01/08 03:37:59 1.58 +++ jsr166/src/test/tck/ConcurrentHashMapTest.java 2019/09/29 20:40:48 1.62 @@ -28,8 +28,6 @@ public class ConcurrentHashMapTest exten class Implementation implements MapImplementation { public Class klazz() { return ConcurrentHashMap.class; } public Map emptyMap() { return new ConcurrentHashMap(); } - public Object makeKey(int i) { return i; } - public Object makeValue(int i) { return i; } public boolean isConcurrent() { return true; } public boolean permitsNullKeys() { return false; } public boolean permitsNullValues() { return false; } @@ -838,4 +836,20 @@ public class ConcurrentHashMapTest exten assertEquals(mapSize, map.size()); } + public void testReentrantComputeIfAbsent() { + ConcurrentHashMap 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 map, + Integer key) { + return (key % 5 == 0) ? key : + map.computeIfAbsent(key + 1, k -> findValue(map, k)); + } + }