Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/util/Collections/WrappedNull.java
41149 views
1
/*
2
* Copyright (c) 1999, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* 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.Arrays;
32
import java.util.Collection;
33
import java.util.Collections;
34
import java.util.List;
35
import java.util.Map;
36
import java.util.Set;
37
import java.util.SortedMap;
38
import java.util.SortedSet;
39
import java.util.TreeMap;
40
import java.util.TreeSet;
41
42
public class WrappedNull {
43
public static void main(String[] args) throws Exception {
44
boolean testSucceeded = false;
45
try {
46
List l = Arrays.asList(null);
47
}
48
catch (NullPointerException e) {
49
testSucceeded = true;
50
}
51
if (!testSucceeded)
52
throw new Exception("Arrays.asList");
53
54
testSucceeded = false;
55
try {
56
Collection c = Collections.unmodifiableCollection(null);
57
}
58
catch (NullPointerException e) {
59
testSucceeded = true;
60
}
61
if (!testSucceeded)
62
throw new Exception("unmodifiableCollection");
63
64
testSucceeded = false;
65
try {
66
Set c = Collections.unmodifiableSet(null);
67
}
68
catch (NullPointerException e) {
69
testSucceeded = true;
70
}
71
if (!testSucceeded)
72
throw new Exception("unmodifiableSet");
73
74
testSucceeded = false;
75
try {
76
List c = Collections.unmodifiableList(null);
77
}
78
catch (NullPointerException e) {
79
testSucceeded = true;
80
}
81
if (!testSucceeded)
82
throw new Exception("unmodifiableList");
83
84
testSucceeded = false;
85
try {
86
Map c = Collections.unmodifiableMap(null);
87
}
88
catch (NullPointerException e) {
89
testSucceeded = true;
90
}
91
if (!testSucceeded)
92
throw new Exception("unmodifiableMap");
93
94
testSucceeded = false;
95
try {
96
SortedSet c = Collections.unmodifiableSortedSet(null);
97
}
98
catch (NullPointerException e) {
99
testSucceeded = true;
100
}
101
if (!testSucceeded)
102
throw new Exception("unmodifiableSortedSet");
103
104
testSucceeded = false;
105
try {
106
SortedMap c = Collections.unmodifiableSortedMap(null);
107
}
108
catch (NullPointerException e) {
109
testSucceeded = true;
110
}
111
if (!testSucceeded)
112
throw new Exception("unmodifiableSortedMap");
113
114
testSucceeded = false;
115
try {
116
Collection c = Collections.synchronizedCollection(null);
117
}
118
catch (NullPointerException e) {
119
testSucceeded = true;
120
}
121
if (!testSucceeded)
122
throw new Exception("synchronizedCollection");
123
124
testSucceeded = false;
125
try {
126
Set c = Collections.synchronizedSet(null);
127
}
128
catch (NullPointerException e) {
129
testSucceeded = true;
130
}
131
if (!testSucceeded)
132
throw new Exception("synchronizedSet");
133
134
testSucceeded = false;
135
try {
136
List c = Collections.synchronizedList(null);
137
}
138
catch (NullPointerException e) {
139
testSucceeded = true;
140
}
141
if (!testSucceeded)
142
throw new Exception("synchronizedList");
143
144
testSucceeded = false;
145
try {
146
Map c = Collections.synchronizedMap(null);
147
}
148
catch (NullPointerException e) {
149
testSucceeded = true;
150
}
151
if (!testSucceeded)
152
throw new Exception("synchronizedMap");
153
154
testSucceeded = false;
155
try {
156
SortedSet c = Collections.synchronizedSortedSet(null);
157
}
158
catch (NullPointerException e) {
159
testSucceeded = true;
160
}
161
if (!testSucceeded)
162
throw new Exception("synchronizedSortedSet");
163
164
testSucceeded = false;
165
try {
166
SortedMap c = Collections.synchronizedSortedMap(null);
167
}
168
catch (NullPointerException e) {
169
testSucceeded = true;
170
}
171
if (!testSucceeded)
172
throw new Exception("synchronizedSortedMap");
173
174
// Make sure that non-null arguments don't throw exc.
175
List l = Arrays.asList(new Object[0]);
176
Collection c = Collections.unmodifiableCollection(
177
Collections.EMPTY_SET);
178
Set s = Collections.unmodifiableSet(Collections.EMPTY_SET);
179
l = Collections.unmodifiableList(Collections.EMPTY_LIST);
180
Map m = Collections.unmodifiableMap(Collections.EMPTY_MAP);
181
SortedSet ss = Collections.unmodifiableSortedSet(new TreeSet());
182
SortedMap sm = Collections.unmodifiableSortedMap(new TreeMap());
183
184
c = Collections.synchronizedCollection(Collections.EMPTY_SET);
185
s = Collections.synchronizedSet(Collections.EMPTY_SET);
186
l = Collections.synchronizedList(Collections.EMPTY_LIST);
187
m = Collections.synchronizedMap(Collections.EMPTY_MAP);
188
ss = Collections.synchronizedSortedSet(new TreeSet());
189
sm = Collections.synchronizedSortedMap(new TreeMap());
190
}
191
}
192
193