jdk/test/java/util/EnumMap/UniqueNullValue.java
author jlahoda
Wed, 12 Dec 2012 20:26:56 +0100
changeset 14803 88347e495d34
parent 11690 74cf5384d069
permissions -rw-r--r--
8004504: ListBuffer could reuse List.nil() as the sentinel element Summary: ListBuffer.last now points to the last elements with client data, or null if none. Reviewed-by: jjg, mcimadamore
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11690
74cf5384d069 7123229: (coll) EnumMap.containsValue(null) returns true
ngmr
parents:
diff changeset
     1
/*
74cf5384d069 7123229: (coll) EnumMap.containsValue(null) returns true
ngmr
parents:
diff changeset
     2
 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
74cf5384d069 7123229: (coll) EnumMap.containsValue(null) returns true
ngmr
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
74cf5384d069 7123229: (coll) EnumMap.containsValue(null) returns true
ngmr
parents:
diff changeset
     4
 *
74cf5384d069 7123229: (coll) EnumMap.containsValue(null) returns true
ngmr
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
74cf5384d069 7123229: (coll) EnumMap.containsValue(null) returns true
ngmr
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
74cf5384d069 7123229: (coll) EnumMap.containsValue(null) returns true
ngmr
parents:
diff changeset
     7
 * published by the Free Software Foundation.
74cf5384d069 7123229: (coll) EnumMap.containsValue(null) returns true
ngmr
parents:
diff changeset
     8
 *
74cf5384d069 7123229: (coll) EnumMap.containsValue(null) returns true
ngmr
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
74cf5384d069 7123229: (coll) EnumMap.containsValue(null) returns true
ngmr
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
74cf5384d069 7123229: (coll) EnumMap.containsValue(null) returns true
ngmr
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
74cf5384d069 7123229: (coll) EnumMap.containsValue(null) returns true
ngmr
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
74cf5384d069 7123229: (coll) EnumMap.containsValue(null) returns true
ngmr
parents:
diff changeset
    13
 * accompanied this code).
74cf5384d069 7123229: (coll) EnumMap.containsValue(null) returns true
ngmr
parents:
diff changeset
    14
 *
74cf5384d069 7123229: (coll) EnumMap.containsValue(null) returns true
ngmr
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
74cf5384d069 7123229: (coll) EnumMap.containsValue(null) returns true
ngmr
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
74cf5384d069 7123229: (coll) EnumMap.containsValue(null) returns true
ngmr
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
74cf5384d069 7123229: (coll) EnumMap.containsValue(null) returns true
ngmr
parents:
diff changeset
    18
 *
74cf5384d069 7123229: (coll) EnumMap.containsValue(null) returns true
ngmr
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
74cf5384d069 7123229: (coll) EnumMap.containsValue(null) returns true
ngmr
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
74cf5384d069 7123229: (coll) EnumMap.containsValue(null) returns true
ngmr
parents:
diff changeset
    21
 * questions.
74cf5384d069 7123229: (coll) EnumMap.containsValue(null) returns true
ngmr
parents:
diff changeset
    22
 */
74cf5384d069 7123229: (coll) EnumMap.containsValue(null) returns true
ngmr
parents:
diff changeset
    23
74cf5384d069 7123229: (coll) EnumMap.containsValue(null) returns true
ngmr
parents:
diff changeset
    24
/*
74cf5384d069 7123229: (coll) EnumMap.containsValue(null) returns true
ngmr
parents:
diff changeset
    25
 * Portions Copyright (c) 2012, IBM Corporation
74cf5384d069 7123229: (coll) EnumMap.containsValue(null) returns true
ngmr
parents:
diff changeset
    26
 */
74cf5384d069 7123229: (coll) EnumMap.containsValue(null) returns true
ngmr
parents:
diff changeset
    27
74cf5384d069 7123229: (coll) EnumMap.containsValue(null) returns true
ngmr
parents:
diff changeset
    28
/*
74cf5384d069 7123229: (coll) EnumMap.containsValue(null) returns true
ngmr
parents:
diff changeset
    29
 * @test
74cf5384d069 7123229: (coll) EnumMap.containsValue(null) returns true
ngmr
parents:
diff changeset
    30
 * @bug 7123229
74cf5384d069 7123229: (coll) EnumMap.containsValue(null) returns true
ngmr
parents:
diff changeset
    31
 * @summary (coll) EnumMap.containsValue(null) returns true
74cf5384d069 7123229: (coll) EnumMap.containsValue(null) returns true
ngmr
parents:
diff changeset
    32
 * @author ngmr
74cf5384d069 7123229: (coll) EnumMap.containsValue(null) returns true
ngmr
parents:
diff changeset
    33
 */
74cf5384d069 7123229: (coll) EnumMap.containsValue(null) returns true
ngmr
parents:
diff changeset
    34
74cf5384d069 7123229: (coll) EnumMap.containsValue(null) returns true
ngmr
parents:
diff changeset
    35
import java.util.EnumMap;
74cf5384d069 7123229: (coll) EnumMap.containsValue(null) returns true
ngmr
parents:
diff changeset
    36
import java.util.Map;
74cf5384d069 7123229: (coll) EnumMap.containsValue(null) returns true
ngmr
parents:
diff changeset
    37
74cf5384d069 7123229: (coll) EnumMap.containsValue(null) returns true
ngmr
parents:
diff changeset
    38
public class UniqueNullValue {
74cf5384d069 7123229: (coll) EnumMap.containsValue(null) returns true
ngmr
parents:
diff changeset
    39
    static enum TestEnum { e00, e01 }
74cf5384d069 7123229: (coll) EnumMap.containsValue(null) returns true
ngmr
parents:
diff changeset
    40
74cf5384d069 7123229: (coll) EnumMap.containsValue(null) returns true
ngmr
parents:
diff changeset
    41
    public static void main(String[] args) {
74cf5384d069 7123229: (coll) EnumMap.containsValue(null) returns true
ngmr
parents:
diff changeset
    42
        Map<TestEnum, Integer> map = new EnumMap<>(TestEnum.class);
74cf5384d069 7123229: (coll) EnumMap.containsValue(null) returns true
ngmr
parents:
diff changeset
    43
74cf5384d069 7123229: (coll) EnumMap.containsValue(null) returns true
ngmr
parents:
diff changeset
    44
        map.put(TestEnum.e00, 0);
74cf5384d069 7123229: (coll) EnumMap.containsValue(null) returns true
ngmr
parents:
diff changeset
    45
        if (false == map.containsValue(0)) {
74cf5384d069 7123229: (coll) EnumMap.containsValue(null) returns true
ngmr
parents:
diff changeset
    46
            throw new RuntimeException("EnumMap unexpectedly missing 0 value");
74cf5384d069 7123229: (coll) EnumMap.containsValue(null) returns true
ngmr
parents:
diff changeset
    47
        }
74cf5384d069 7123229: (coll) EnumMap.containsValue(null) returns true
ngmr
parents:
diff changeset
    48
        if (map.containsValue(null)) {
74cf5384d069 7123229: (coll) EnumMap.containsValue(null) returns true
ngmr
parents:
diff changeset
    49
            throw new RuntimeException("EnumMap unexpectedly holds null value");
74cf5384d069 7123229: (coll) EnumMap.containsValue(null) returns true
ngmr
parents:
diff changeset
    50
        }
74cf5384d069 7123229: (coll) EnumMap.containsValue(null) returns true
ngmr
parents:
diff changeset
    51
74cf5384d069 7123229: (coll) EnumMap.containsValue(null) returns true
ngmr
parents:
diff changeset
    52
        map.put(TestEnum.e00, null);
74cf5384d069 7123229: (coll) EnumMap.containsValue(null) returns true
ngmr
parents:
diff changeset
    53
        if (map.containsValue(0)) {
74cf5384d069 7123229: (coll) EnumMap.containsValue(null) returns true
ngmr
parents:
diff changeset
    54
            throw new RuntimeException("EnumMap unexpectedly holds 0 value");
74cf5384d069 7123229: (coll) EnumMap.containsValue(null) returns true
ngmr
parents:
diff changeset
    55
        }
74cf5384d069 7123229: (coll) EnumMap.containsValue(null) returns true
ngmr
parents:
diff changeset
    56
        if (false == map.containsValue(null)) {
74cf5384d069 7123229: (coll) EnumMap.containsValue(null) returns true
ngmr
parents:
diff changeset
    57
            throw new RuntimeException("EnumMap unexpectedly missing null value");
74cf5384d069 7123229: (coll) EnumMap.containsValue(null) returns true
ngmr
parents:
diff changeset
    58
        }
74cf5384d069 7123229: (coll) EnumMap.containsValue(null) returns true
ngmr
parents:
diff changeset
    59
    }
74cf5384d069 7123229: (coll) EnumMap.containsValue(null) returns true
ngmr
parents:
diff changeset
    60
}