Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-7123229

(coll) EnumMap.containsValue(null) returns true

XMLWordPrintable

    • b140
    • 7
    • b25
    • x86
    • linux
    • Verified

        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 ----------

              alanb Alan Bateman
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: