JDK-6272521 : ConcurrentHashMap.remove(x,null) might remove x
  • Type: Bug
  • Status: Closed
  • Resolution: Fixed
  • Component: core-libs
  • Sub-Component: java.util.concurrent
  • Priority: P3
  • Affected Version: 6
  • OS: generic
  • CPU: generic
  • Submit Date: 2005-05-18
  • Updated Date: 2010-04-02
  • Resolved Date: 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 Availabitlity Release.

To download the current JDK release, click here.
JDK 6
6 b51Fixed
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