United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6312056 ConcurrentHashMap.entrySet().iterator() can return entry with never-existent value
JDK-6312056 : ConcurrentHashMap.entrySet().iterator() can return entry with never-existent value

Details
Type:
Bug
Submit Date:
2005-08-17
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.*;

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

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
EVALUATION

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



Hardware and Software, Engineered to Work Together