I've noticed a serious difference in the semantics of the ConcurrentHashMap.computeIfAbsent method between Oracle's JDK and Open JDK. This is surprising, so I wanted to make note of it, and see whether others have noticed this issue, or if I'm misinterpreting something.
According to the Javadoc for Oracle's JDK (beginning with v8, and continuing to v15) the semantics for invocation of the mappingFunction are:
The entire method invocation is performed atomically, so the function is applied at most once per key.
However, I noticed the function being invoked twice in my program when the key was accessed simultaneously from two different threads. Digging deeper, I noticed that Open JDK's documentation specifies different semantics:
The entire method invocation is performed atomically. The supplied function is invoked exactly once per invocation of this method if the key is absent, else not at all.
That's quite a big difference in behavior, and consistent with what I observed in my program. Open JDK's implementation is far less useful, in my opinion, because the resource being constructed is oftentimes very expensive and it should be created at most once.