JDK-7123229 : (coll) EnumMap.containsValue(null) returns true
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util:collections
  • Affected Version: 7
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: linux
  • CPU: x86
  • Submitted: 2011-12-20
  • Updated: 2012-10-08
  • Resolved: 2012-05-09
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 Availability Release.

To download the current JDK release, click here.
JDK 7 JDK 8
7u4Fixed 8 b25Fixed
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.7.0"
Java(TM) SE Runtime Environment (build 1.7.0-b147)
Java HotSpot(TM) 64-Bit Server VM (build 21.0-b17, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
All OSes are affected. It is a bug in the source of java.util.EnumMap.

A DESCRIPTION OF THE PROBLEM :
I have an EnumMap: EnumMap<EnumType, Integer>. If there is an entry (EnumType.Type, Integer(0)) in the map, containsValue(null) will return true even if there is no null value among value set.

I've checked the source of EnumMap in 1.6 and 1.7 java and I've found a main difference:
"private static final Object NULL = new Object();" has been replaced to "private static final Object NULL = new Integer(0);" in 1.7.
When the containsValue is called, the incoming arg(null) is replaced to this NULL(Integer(0)) value in maskNull() method.. The iteration will compare all items to arg and arg (Integer(0)) will be equal to Integer(0), one of the values in the map. And there is no null in Map.


REGRESSION.  Last worked in version 7

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Use the attached source code. It will result false with 1.6 JRE and true with 1.7.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The attached source should provide false independently from JRE  version

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.util.EnumMap;
import java.util.Map;

public class EnumMapTest {

	enum EnumType {
		ZERO, ONE, TWO
	}
	
	public static void main(String[] args) {
		Map<EnumType, Integer> map = new EnumMap<EnumType, Integer>(EnumType.class);
		map.put(EnumType.ZERO, 0);
		System.out.println(map.containsValue(null));
	}
}
---------- END SOURCE ----------

Comments
EVALUATION http://hg.openjdk.java.net/jdk8/tl/jdk/rev/863a20b0bf08
31-01-2012

EVALUATION Appears to be a side effect of 6312706.
21-12-2011