-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
8u121
-
x86
-
other
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.
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.
- duplicates
-
JDK-8174087 Implementation requirements code example for ConcurrentMap.putIfAbsent() returns incorrect value
- Closed