JDK-6269785 : ConcurrentMap.replace,remove methods "equivalent" code not correct when elt not in map
Type:Bug
Component:core-libs
Sub-Component:java.util.concurrent
Affected Version:6
Priority:P4
Status:Resolved
Resolution:Fixed
OS:generic
CPU:generic
Submitted:2005-05-12
Updated:2010-04-02
Resolved:2005-09-04
The Version table provides details related to the release that this issue/RFE will be addressed.
Unresolved : Release in which this issue/RFE will be addressed. Resolved: Release in which this issue/RFE has been resolved. Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.
The "This is equivalent to" code in replace(key, value) and
replace(key, oldValue, newValue) would throw a NullPointerException.
###@###.### 2005-05-12 23:52:01 GMT
Comments
EVALUATION
Will be fixed as part of the jsr166x project.
###@###.### 2005-05-12 23:53:05 GMT
12-05-2005
SUGGESTED FIX
--- util/concurrent/ConcurrentHashMap.java 2 May 2005 21:51:38 -0000 1.66
+++ util/concurrent/ConcurrentHashMap.java 12 May 2005 23:44:06 -0000
@@ -937,7 +938,7 @@
* Remove entry for key only if currently mapped to given value.
* This is equivalent to
* <pre>
- * if (map.get(key).equals(value)) {
+ * if (map.containsKey(key) && map.get(key).equals(value)) {
* map.remove(key);
* return true;
* } else return false;</pre>
@@ -958,7 +959,7 @@
* Replaces entry for key only if currently mapped to given value.
* This is equivalent to
* <pre>
- * if (map.get(key).equals(oldValue)) {
+ * if (map.containsKey(key) && map.get(key).equals(oldValue)) {
* map.put(key, newValue);
* return true;
* } else return false;</pre>
###@###.### 2005-05-12 23:52:01 GMT