-
Bug
-
Resolution: Fixed
-
P4
-
8u251, 14
A DESCRIPTION OF THE PROBLEM :
The implementation requirements for Map::compute reads:
V oldValue = map.get(key);
V newValue = remappingFunction.apply(key, oldValue);
if (oldValue != null ) {
if (newValue != null)
map.put(key, newValue);
else
map.remove(key);
} else {
if (newValue != null)
map.put(key, newValue);
else
return null;
}
However, it's weird that the code only returns when (oldValue == null && newValue == null). The problem is that the code doesn't return anything otherwise. I think the better way is:
V oldValue = map.get(key);
V newValue = remappingFunction.apply(key, oldValue);
if (oldValue != null ) {
if (newValue != null)
map.put(key, newValue);
else
map.remove(key);
} else {
if (newValue != null)
map.put(key, newValue);
}
return newValue;
PS. This issue meant to target the documentation of the core libraries, but I couldn't find it in the "Subcomponent" list. So I chose "guides: Documentation related to Guides" instead.
FREQUENCY : always
The implementation requirements for Map::compute reads:
V oldValue = map.get(key);
V newValue = remappingFunction.apply(key, oldValue);
if (oldValue != null ) {
if (newValue != null)
map.put(key, newValue);
else
map.remove(key);
} else {
if (newValue != null)
map.put(key, newValue);
else
return null;
}
However, it's weird that the code only returns when (oldValue == null && newValue == null). The problem is that the code doesn't return anything otherwise. I think the better way is:
V oldValue = map.get(key);
V newValue = remappingFunction.apply(key, oldValue);
if (oldValue != null ) {
if (newValue != null)
map.put(key, newValue);
else
map.remove(key);
} else {
if (newValue != null)
map.put(key, newValue);
}
return newValue;
PS. This issue meant to target the documentation of the core libraries, but I couldn't find it in the "Subcomponent" list. So I chose "guides: Documentation related to Guides" instead.
FREQUENCY : always
- csr for
-
JDK-8257768 Documentation for Map::compute contains confusing implementation requirements
-
- Closed
-