United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6272521 ConcurrentHashMap.remove(x,null) might remove x
JDK-6272521 : ConcurrentHashMap.remove(x,null) might remove x

Details
Type:
Bug
Submit Date:
2005-05-18
Status:
Closed
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:
P3
Resolution:
Fixed
Affected Versions:
6
Fixed Versions:

Related Reports

Sub Tasks

Description
This program:

import java.util.*;
import java.util.concurrent.*;
import static java.lang.System.out;

public class tt {
    public static void main(String[] args) throws Exception {
	ConcurrentMap<Long,Long>m = new ConcurrentHashMap<Long,Long>();
	out.println(m.put(1L,2L));
	out.println(m.remove(1L,null));
	out.println(m.remove(1L,null));

    }
}


should print
null
false
false

Instead, it prints
null
true
false

###@###.### 2005-05-18 18:05:40 GMT

                                    

Comments
SUGGESTED FIX

    public boolean remove(Object key, Object value) {
        if (value == null)
            return false;
        int hash = hash(key);
        return segmentFor(hash).remove(key, hash, value) != null;
    }

###@###.### 2005-05-18 18:05:41 GMT
                                     
2005-05-18
EVALUATION

Good catch.  Will be fixed as part of the jsr166x project.
###@###.### 2005-05-18 18:05:41 GMT
                                     
2005-05-18



Hardware and Software, Engineered to Work Together