JDK-8175523 : Documentation error for java.util.concurrent.ConcurrentMap#computeIfAbsent
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util.concurrent
  • Affected Version: 8u121
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: other
  • CPU: x86
  • Submitted: 2017-02-22
  • Updated: 2017-03-08
  • Resolved: 2017-02-23
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
1.8.0_102

ADDITIONAL OS VERSION INFORMATION :
Not OS related

A DESCRIPTION OF THE PROBLEM :
The documentation of  java.util.concurrent.ConcurrentMap#computeIfAbsent contains a snippet of code:

if (map.get(key) == null) {
     V newValue = mappingFunction.apply(key);
     if (newValue != null)
         return map.putIfAbsent(key, newValue);
 }

This is contradictory with the return information that says:
returns the current (existing or computed) value associated with the specified key, or null if the computed value is null

putIfAbsent returns the previous value of the map, not the new one.
The snipped is incorrect because the implementation returns the new value not the old one.


REPRODUCIBILITY :
This bug can be reproduced always.


Comments
This is a duplicate of JDK-8174087
23-02-2017