--- jsr166/src/test/tck/ConcurrentHashMapTest.java 2018/01/08 03:37:59 1.58 +++ jsr166/src/test/tck/ConcurrentHashMapTest.java 2018/10/05 19:01:35 1.59 @@ -838,4 +838,23 @@ 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"); + } catch (IllegalStateException ex) { + } + } + + private Integer findValue(ConcurrentHashMap map, + Integer key) { + return (key % 5 == 0) ? key : + map.computeIfAbsent(key + 1, k -> findValue(map, k)); + } + }