ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/jtreg/util/Collections/WrappedNull.java
Revision: 1.1
Committed: Tue Sep 1 01:24:16 2009 UTC (14 years, 8 months ago) by jsr166
Branch: MAIN
Log Message:
import tests from openjdk

File Contents

# User Rev Content
1 jsr166 1.1 /*
2     * Copyright 1999 Sun Microsystems, Inc. All Rights Reserved.
3     * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4     *
5     * This code is free software; you can redistribute it and/or modify it
6     * under the terms of the GNU General Public License version 2 only, as
7     * published by the Free Software Foundation.
8     *
9     * This code is distributed in the hope that it will be useful, but WITHOUT
10     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11     * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12     * version 2 for more details (a copy is included in the LICENSE file that
13     * accompanied this code).
14     *
15     * You should have received a copy of the GNU General Public License version
16     * 2 along with this work; if not, write to the Free Software Foundation,
17     * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18     *
19     * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20     * CA 95054 USA or visit www.sun.com if you need additional information or
21     * have any questions.
22     */
23    
24     /*
25     * @test
26     * @bug 4189641
27     * @summary Wrapping a null collection/array should blow up sooner
28     * rather than later
29     */
30    
31     import java.util.*;
32    
33     public class WrappedNull {
34     public static void main(String argv[]) throws Exception {
35     boolean testSucceeded = false;
36     try{
37     List l = Arrays.asList(null);
38     }
39     catch (NullPointerException e) {
40     testSucceeded = true;
41     }
42     if(!testSucceeded)
43     throw new Exception("Arrays.asList");
44    
45     testSucceeded = false;
46     try{
47     Collection c = Collections.unmodifiableCollection(null);
48     }
49     catch (NullPointerException e) {
50     testSucceeded = true;
51     }
52     if(!testSucceeded)
53     throw new Exception("unmodifiableCollection");
54    
55     testSucceeded = false;
56     try{
57     Set c = Collections.unmodifiableSet(null);
58     }
59     catch (NullPointerException e) {
60     testSucceeded = true;
61     }
62     if(!testSucceeded)
63     throw new Exception("unmodifiableSet");
64    
65     testSucceeded = false;
66     try{
67     List c = Collections.unmodifiableList(null);
68     }
69     catch (NullPointerException e) {
70     testSucceeded = true;
71     }
72     if(!testSucceeded)
73     throw new Exception("unmodifiableList");
74    
75     testSucceeded = false;
76     try{
77     Map c = Collections.unmodifiableMap(null);
78     }
79     catch (NullPointerException e) {
80     testSucceeded = true;
81     }
82     if(!testSucceeded)
83     throw new Exception("unmodifiableMap");
84    
85     testSucceeded = false;
86     try{
87     SortedSet c = Collections.unmodifiableSortedSet(null);
88     }
89     catch (NullPointerException e) {
90     testSucceeded = true;
91     }
92     if(!testSucceeded)
93     throw new Exception("unmodifiableSortedSet");
94    
95     testSucceeded = false;
96     try{
97     SortedMap c = Collections.unmodifiableSortedMap(null);
98     }
99     catch (NullPointerException e) {
100     testSucceeded = true;
101     }
102     if(!testSucceeded)
103     throw new Exception("unmodifiableSortedMap");
104    
105     testSucceeded = false;
106     try{
107     Collection c = Collections.synchronizedCollection(null);
108     }
109     catch (NullPointerException e) {
110     testSucceeded = true;
111     }
112     if(!testSucceeded)
113     throw new Exception("synchronizedCollection");
114    
115     testSucceeded = false;
116     try{
117     Set c = Collections.synchronizedSet(null);
118     }
119     catch (NullPointerException e) {
120     testSucceeded = true;
121     }
122     if(!testSucceeded)
123     throw new Exception("synchronizedSet");
124    
125     testSucceeded = false;
126     try{
127     List c = Collections.synchronizedList(null);
128     }
129     catch (NullPointerException e) {
130     testSucceeded = true;
131     }
132     if(!testSucceeded)
133     throw new Exception("synchronizedList");
134    
135     testSucceeded = false;
136     try{
137     Map c = Collections.synchronizedMap(null);
138     }
139     catch (NullPointerException e) {
140     testSucceeded = true;
141     }
142     if(!testSucceeded)
143     throw new Exception("synchronizedMap");
144    
145     testSucceeded = false;
146     try{
147     SortedSet c = Collections.synchronizedSortedSet(null);
148     }
149     catch (NullPointerException e) {
150     testSucceeded = true;
151     }
152     if(!testSucceeded)
153     throw new Exception("synchronizedSortedSet");
154    
155     testSucceeded = false;
156     try{
157     SortedMap c = Collections.synchronizedSortedMap(null);
158     }
159     catch (NullPointerException e) {
160     testSucceeded = true;
161     }
162     if(!testSucceeded)
163     throw new Exception("synchronizedSortedMap");
164    
165     // Make sure that non-null arguments don't throw exc.
166     List l = Arrays.asList(new Object[0]);
167     Collection c = Collections.unmodifiableCollection(
168     Collections.EMPTY_SET);
169     Set s = Collections.unmodifiableSet(Collections.EMPTY_SET);
170     l = Collections.unmodifiableList(Collections.EMPTY_LIST);
171     Map m = Collections.unmodifiableMap(Collections.EMPTY_MAP);
172     SortedSet ss = Collections.unmodifiableSortedSet(new TreeSet());
173     SortedMap sm = Collections.unmodifiableSortedMap(new TreeMap());
174    
175     c = Collections.synchronizedCollection(Collections.EMPTY_SET);
176     s = Collections.synchronizedSet(Collections.EMPTY_SET);
177     l = Collections.synchronizedList(Collections.EMPTY_LIST);
178     m = Collections.synchronizedMap(Collections.EMPTY_MAP);
179     ss = Collections.synchronizedSortedSet(new TreeSet());
180     sm = Collections.synchronizedSortedMap(new TreeMap());
181     }
182     }