author | alanb |
Fri, 11 Jan 2013 20:19:55 +0000 (2013-01-11) | |
changeset 15254 | 3997a6f357cb |
parent 14016 | 56be5085fc31 |
child 32649 | 2ee9017c7597 |
permissions | -rw-r--r-- |
14016
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
1 |
/* |
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
2 |
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. |
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
4 |
* |
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
8 |
* |
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
13 |
* accompanied this code). |
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
14 |
* |
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
18 |
* |
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
21 |
* questions. |
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
22 |
*/ |
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
23 |
|
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
24 |
/** |
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
25 |
* @test |
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
26 |
* @bug 7197642 |
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
27 |
* @summary test ServiceLoader.load methods for NullPointerException. |
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
28 |
*/ |
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
29 |
import java.util.ServiceLoader; |
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
30 |
import java.util.Arrays; |
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
31 |
|
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
32 |
public final class NPE { |
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
33 |
static abstract class Test { |
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
34 |
String name; |
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
35 |
|
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
36 |
Test(String name) { this.name = name; } |
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
37 |
|
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
38 |
abstract void run(); |
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
39 |
} |
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
40 |
|
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
41 |
static Test load = new Test("ServiceLoader.load(null)") { |
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
42 |
void run() { ServiceLoader.load(null); } |
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
43 |
}; |
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
44 |
|
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
45 |
static Test loadWithClassLoader = new Test("ServiceLoader.load(null, loader)") { |
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
46 |
void run() { ServiceLoader.load(null, NPE.class.getClassLoader()); } |
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
47 |
}; |
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
48 |
|
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
49 |
static Test loadInstalled = new Test("ServiceLoader.loadInstalled(null)") { |
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
50 |
void run() { ServiceLoader.loadInstalled(null); } |
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
51 |
}; |
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
52 |
|
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
53 |
public static void main(String[] args) throws Exception { |
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
54 |
for (Test t : Arrays.asList(load, loadWithClassLoader, loadInstalled)) { |
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
55 |
NullPointerException caught = null; |
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
56 |
try { |
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
57 |
t.run(); |
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
58 |
} catch (NullPointerException e) { |
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
59 |
caught = e; |
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
60 |
} |
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
61 |
if (caught == null) { |
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
62 |
throw new RuntimeException("NullPointerException expected for method invocation of " + t.name); |
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
63 |
} |
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
64 |
} |
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
65 |
} |
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
66 |
} |
56be5085fc31
7197642: (sl) ServiceLoader.load(null) doesn't throw NPE
psandoz
parents:
diff
changeset
|
67 |