JDK-6312056 : ConcurrentHashMap.entrySet().iterator() can return entry with never-existent value
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util.concurrent
  • Affected Version: 6
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2005-08-17
  • 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 Availabitlity Release.

To download the current JDK release, click here.
JDK 6
6 b51Fixed
Description
This program

------------------------------------------------------------
import java.util.*;
import java.util.concurrent.*;

public class Bug {
    public static void main(String[] args) throws Exception {
	Map m = new ConcurrentHashMap();
	m.put(1,2);
	Iterator it = m.entrySet().iterator();
	if (it.hasNext()) {
	    m.remove(1); // sneaky
	    System.out.println(it.next());
	}
    }
}
------------------------------------------------------------
prints

1=null

which is very surprising, since 1 was never mapped to null,
and in fact, it could never be.

Comments
EVALUATION Doug Lea is providing a fix.
2005-08-21

EVALUATION The iterator keeps the last entry, but does not take into account the possibility that it has been deleted between hasNext() and next()
2005-08-18