United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6269785 ConcurrentMap.replace,remove methods "equivalent" code not correct when elt not in map
JDK-6269785 : ConcurrentMap.replace,remove methods "equivalent" code not correct when elt not in map

Details
Type:
Bug
Submit Date:
2005-05-12
Status:
Resolved
Updated Date:
2010-04-02
Project Name:
JDK
Resolved Date:
2005-09-04
Component:
core-libs
OS:
generic
Sub-Component:
java.util.concurrent
CPU:
generic
Priority:
P4
Resolution:
Fixed
Affected Versions:
6
Fixed Versions:

Related Reports

Sub Tasks

Description
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
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
                                     
2005-05-12
EVALUATION

Will be fixed as part of the jsr166x project.
###@###.### 2005-05-12 23:53:05 GMT
                                     
2005-05-12



Hardware and Software, Engineered to Work Together