Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/util/Collections/WrappedNull.java
38812 views
/*1* Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 418964126* @summary Wrapping a null collection/array should blow up sooner27* rather than later28*/2930import java.util.*;3132public class WrappedNull {33public static void main(String argv[]) throws Exception {34boolean testSucceeded = false;35try{36List l = Arrays.asList(null);37}38catch (NullPointerException e) {39testSucceeded = true;40}41if(!testSucceeded)42throw new Exception("Arrays.asList");4344testSucceeded = false;45try{46Collection c = Collections.unmodifiableCollection(null);47}48catch (NullPointerException e) {49testSucceeded = true;50}51if(!testSucceeded)52throw new Exception("unmodifiableCollection");5354testSucceeded = false;55try{56Set c = Collections.unmodifiableSet(null);57}58catch (NullPointerException e) {59testSucceeded = true;60}61if(!testSucceeded)62throw new Exception("unmodifiableSet");6364testSucceeded = false;65try{66List c = Collections.unmodifiableList(null);67}68catch (NullPointerException e) {69testSucceeded = true;70}71if(!testSucceeded)72throw new Exception("unmodifiableList");7374testSucceeded = false;75try{76Map c = Collections.unmodifiableMap(null);77}78catch (NullPointerException e) {79testSucceeded = true;80}81if(!testSucceeded)82throw new Exception("unmodifiableMap");8384testSucceeded = false;85try{86SortedSet c = Collections.unmodifiableSortedSet(null);87}88catch (NullPointerException e) {89testSucceeded = true;90}91if(!testSucceeded)92throw new Exception("unmodifiableSortedSet");9394testSucceeded = false;95try{96SortedMap c = Collections.unmodifiableSortedMap(null);97}98catch (NullPointerException e) {99testSucceeded = true;100}101if(!testSucceeded)102throw new Exception("unmodifiableSortedMap");103104testSucceeded = false;105try{106Collection c = Collections.synchronizedCollection(null);107}108catch (NullPointerException e) {109testSucceeded = true;110}111if(!testSucceeded)112throw new Exception("synchronizedCollection");113114testSucceeded = false;115try{116Set c = Collections.synchronizedSet(null);117}118catch (NullPointerException e) {119testSucceeded = true;120}121if(!testSucceeded)122throw new Exception("synchronizedSet");123124testSucceeded = false;125try{126List c = Collections.synchronizedList(null);127}128catch (NullPointerException e) {129testSucceeded = true;130}131if(!testSucceeded)132throw new Exception("synchronizedList");133134testSucceeded = false;135try{136Map c = Collections.synchronizedMap(null);137}138catch (NullPointerException e) {139testSucceeded = true;140}141if(!testSucceeded)142throw new Exception("synchronizedMap");143144testSucceeded = false;145try{146SortedSet c = Collections.synchronizedSortedSet(null);147}148catch (NullPointerException e) {149testSucceeded = true;150}151if(!testSucceeded)152throw new Exception("synchronizedSortedSet");153154testSucceeded = false;155try{156SortedMap c = Collections.synchronizedSortedMap(null);157}158catch (NullPointerException e) {159testSucceeded = true;160}161if(!testSucceeded)162throw new Exception("synchronizedSortedMap");163164// Make sure that non-null arguments don't throw exc.165List l = Arrays.asList(new Object[0]);166Collection c = Collections.unmodifiableCollection(167Collections.EMPTY_SET);168Set s = Collections.unmodifiableSet(Collections.EMPTY_SET);169l = Collections.unmodifiableList(Collections.EMPTY_LIST);170Map m = Collections.unmodifiableMap(Collections.EMPTY_MAP);171SortedSet ss = Collections.unmodifiableSortedSet(new TreeSet());172SortedMap sm = Collections.unmodifiableSortedMap(new TreeMap());173174c = Collections.synchronizedCollection(Collections.EMPTY_SET);175s = Collections.synchronizedSet(Collections.EMPTY_SET);176l = Collections.synchronizedList(Collections.EMPTY_LIST);177m = Collections.synchronizedMap(Collections.EMPTY_MAP);178ss = Collections.synchronizedSortedSet(new TreeSet());179sm = Collections.synchronizedSortedMap(new TreeMap());180}181}182183184