FULL PRODUCT VERSION :
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Darwin mysh.local 16.6.0 Darwin Kernel Version 16.6.0: Fri Apr 14 16:21:16 PDT 2017; root:xnu-3789.60.24~6/RELEASE_X86_64 x86_64
A DESCRIPTION OF THE PROBLEM :
ConcurrentHashMap infinite loops in one condition
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
run the code
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
print result and exit
ACTUAL -
infinite loop
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class CommonTest {
private static Map<Integer, Integer> cache = new ConcurrentHashMap<>();
public static void main(String[] args) {
System.out.println(fibonacci(80));
}
public static int fibonacci(Integer i) {
if (i == 0 || i == 1) {
return i;
}
return cache.computeIfAbsent(i, (key) -> {
System.out.println("Compute fibonacci " + key);
return fibonacci(key - 1) + fibonacci(key - 2);
});
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
replace computeIfAbsent with get-set