author | bchristi |
Tue, 05 Dec 2017 09:44:32 -0800 | |
changeset 48066 | df95bd1fd4b1 |
permissions | -rw-r--r-- |
48066
df95bd1fd4b1
8187222: ClassLoader.getSystemClassLoader not clear if recursive initialization leads to ISE or unspecified error
bchristi
parents:
diff
changeset
|
1 |
/* |
df95bd1fd4b1
8187222: ClassLoader.getSystemClassLoader not clear if recursive initialization leads to ISE or unspecified error
bchristi
parents:
diff
changeset
|
2 |
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. |
df95bd1fd4b1
8187222: ClassLoader.getSystemClassLoader not clear if recursive initialization leads to ISE or unspecified error
bchristi
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
df95bd1fd4b1
8187222: ClassLoader.getSystemClassLoader not clear if recursive initialization leads to ISE or unspecified error
bchristi
parents:
diff
changeset
|
4 |
* |
df95bd1fd4b1
8187222: ClassLoader.getSystemClassLoader not clear if recursive initialization leads to ISE or unspecified error
bchristi
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
df95bd1fd4b1
8187222: ClassLoader.getSystemClassLoader not clear if recursive initialization leads to ISE or unspecified error
bchristi
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
df95bd1fd4b1
8187222: ClassLoader.getSystemClassLoader not clear if recursive initialization leads to ISE or unspecified error
bchristi
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
df95bd1fd4b1
8187222: ClassLoader.getSystemClassLoader not clear if recursive initialization leads to ISE or unspecified error
bchristi
parents:
diff
changeset
|
8 |
* |
df95bd1fd4b1
8187222: ClassLoader.getSystemClassLoader not clear if recursive initialization leads to ISE or unspecified error
bchristi
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
df95bd1fd4b1
8187222: ClassLoader.getSystemClassLoader not clear if recursive initialization leads to ISE or unspecified error
bchristi
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
df95bd1fd4b1
8187222: ClassLoader.getSystemClassLoader not clear if recursive initialization leads to ISE or unspecified error
bchristi
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
df95bd1fd4b1
8187222: ClassLoader.getSystemClassLoader not clear if recursive initialization leads to ISE or unspecified error
bchristi
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
df95bd1fd4b1
8187222: ClassLoader.getSystemClassLoader not clear if recursive initialization leads to ISE or unspecified error
bchristi
parents:
diff
changeset
|
13 |
* accompanied this code). |
df95bd1fd4b1
8187222: ClassLoader.getSystemClassLoader not clear if recursive initialization leads to ISE or unspecified error
bchristi
parents:
diff
changeset
|
14 |
* |
df95bd1fd4b1
8187222: ClassLoader.getSystemClassLoader not clear if recursive initialization leads to ISE or unspecified error
bchristi
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
df95bd1fd4b1
8187222: ClassLoader.getSystemClassLoader not clear if recursive initialization leads to ISE or unspecified error
bchristi
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
df95bd1fd4b1
8187222: ClassLoader.getSystemClassLoader not clear if recursive initialization leads to ISE or unspecified error
bchristi
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
df95bd1fd4b1
8187222: ClassLoader.getSystemClassLoader not clear if recursive initialization leads to ISE or unspecified error
bchristi
parents:
diff
changeset
|
18 |
* |
df95bd1fd4b1
8187222: ClassLoader.getSystemClassLoader not clear if recursive initialization leads to ISE or unspecified error
bchristi
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
df95bd1fd4b1
8187222: ClassLoader.getSystemClassLoader not clear if recursive initialization leads to ISE or unspecified error
bchristi
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
df95bd1fd4b1
8187222: ClassLoader.getSystemClassLoader not clear if recursive initialization leads to ISE or unspecified error
bchristi
parents:
diff
changeset
|
21 |
* questions. |
df95bd1fd4b1
8187222: ClassLoader.getSystemClassLoader not clear if recursive initialization leads to ISE or unspecified error
bchristi
parents:
diff
changeset
|
22 |
*/ |
df95bd1fd4b1
8187222: ClassLoader.getSystemClassLoader not clear if recursive initialization leads to ISE or unspecified error
bchristi
parents:
diff
changeset
|
23 |
|
df95bd1fd4b1
8187222: ClassLoader.getSystemClassLoader not clear if recursive initialization leads to ISE or unspecified error
bchristi
parents:
diff
changeset
|
24 |
/* |
df95bd1fd4b1
8187222: ClassLoader.getSystemClassLoader not clear if recursive initialization leads to ISE or unspecified error
bchristi
parents:
diff
changeset
|
25 |
* @test |
df95bd1fd4b1
8187222: ClassLoader.getSystemClassLoader not clear if recursive initialization leads to ISE or unspecified error
bchristi
parents:
diff
changeset
|
26 |
* @bug 8187222 |
df95bd1fd4b1
8187222: ClassLoader.getSystemClassLoader not clear if recursive initialization leads to ISE or unspecified error
bchristi
parents:
diff
changeset
|
27 |
* @run main/othervm -Djava.system.class.loader=RecursiveSystemLoader RecursiveSystemLoader |
df95bd1fd4b1
8187222: ClassLoader.getSystemClassLoader not clear if recursive initialization leads to ISE or unspecified error
bchristi
parents:
diff
changeset
|
28 |
* @summary Test for IllegalStateException if a custom system loader recursively calls getSystemClassLoader() |
df95bd1fd4b1
8187222: ClassLoader.getSystemClassLoader not clear if recursive initialization leads to ISE or unspecified error
bchristi
parents:
diff
changeset
|
29 |
*/ |
df95bd1fd4b1
8187222: ClassLoader.getSystemClassLoader not clear if recursive initialization leads to ISE or unspecified error
bchristi
parents:
diff
changeset
|
30 |
public class RecursiveSystemLoader extends ClassLoader { |
df95bd1fd4b1
8187222: ClassLoader.getSystemClassLoader not clear if recursive initialization leads to ISE or unspecified error
bchristi
parents:
diff
changeset
|
31 |
public static void main(String[] args) { |
df95bd1fd4b1
8187222: ClassLoader.getSystemClassLoader not clear if recursive initialization leads to ISE or unspecified error
bchristi
parents:
diff
changeset
|
32 |
ClassLoader sys = ClassLoader.getSystemClassLoader(); |
df95bd1fd4b1
8187222: ClassLoader.getSystemClassLoader not clear if recursive initialization leads to ISE or unspecified error
bchristi
parents:
diff
changeset
|
33 |
if (!(sys instanceof RecursiveSystemLoader)) { |
df95bd1fd4b1
8187222: ClassLoader.getSystemClassLoader not clear if recursive initialization leads to ISE or unspecified error
bchristi
parents:
diff
changeset
|
34 |
throw new RuntimeException("Unexpected system classloader: " + sys); |
df95bd1fd4b1
8187222: ClassLoader.getSystemClassLoader not clear if recursive initialization leads to ISE or unspecified error
bchristi
parents:
diff
changeset
|
35 |
} |
df95bd1fd4b1
8187222: ClassLoader.getSystemClassLoader not clear if recursive initialization leads to ISE or unspecified error
bchristi
parents:
diff
changeset
|
36 |
} |
df95bd1fd4b1
8187222: ClassLoader.getSystemClassLoader not clear if recursive initialization leads to ISE or unspecified error
bchristi
parents:
diff
changeset
|
37 |
public RecursiveSystemLoader(ClassLoader classLoader) { |
df95bd1fd4b1
8187222: ClassLoader.getSystemClassLoader not clear if recursive initialization leads to ISE or unspecified error
bchristi
parents:
diff
changeset
|
38 |
super("RecursiveSystemLoader", classLoader); |
df95bd1fd4b1
8187222: ClassLoader.getSystemClassLoader not clear if recursive initialization leads to ISE or unspecified error
bchristi
parents:
diff
changeset
|
39 |
|
df95bd1fd4b1
8187222: ClassLoader.getSystemClassLoader not clear if recursive initialization leads to ISE or unspecified error
bchristi
parents:
diff
changeset
|
40 |
// Calling ClassLoader.getSystemClassLoader() before the VM is booted |
df95bd1fd4b1
8187222: ClassLoader.getSystemClassLoader not clear if recursive initialization leads to ISE or unspecified error
bchristi
parents:
diff
changeset
|
41 |
// should throw an IllegalStateException. |
df95bd1fd4b1
8187222: ClassLoader.getSystemClassLoader not clear if recursive initialization leads to ISE or unspecified error
bchristi
parents:
diff
changeset
|
42 |
try { |
df95bd1fd4b1
8187222: ClassLoader.getSystemClassLoader not clear if recursive initialization leads to ISE or unspecified error
bchristi
parents:
diff
changeset
|
43 |
ClassLoader.getSystemClassLoader(); |
df95bd1fd4b1
8187222: ClassLoader.getSystemClassLoader not clear if recursive initialization leads to ISE or unspecified error
bchristi
parents:
diff
changeset
|
44 |
} catch(IllegalStateException ise) { |
df95bd1fd4b1
8187222: ClassLoader.getSystemClassLoader not clear if recursive initialization leads to ISE or unspecified error
bchristi
parents:
diff
changeset
|
45 |
System.err.println("Caught expected exception:"); |
df95bd1fd4b1
8187222: ClassLoader.getSystemClassLoader not clear if recursive initialization leads to ISE or unspecified error
bchristi
parents:
diff
changeset
|
46 |
ise.printStackTrace(); |
df95bd1fd4b1
8187222: ClassLoader.getSystemClassLoader not clear if recursive initialization leads to ISE or unspecified error
bchristi
parents:
diff
changeset
|
47 |
return; |
df95bd1fd4b1
8187222: ClassLoader.getSystemClassLoader not clear if recursive initialization leads to ISE or unspecified error
bchristi
parents:
diff
changeset
|
48 |
} |
df95bd1fd4b1
8187222: ClassLoader.getSystemClassLoader not clear if recursive initialization leads to ISE or unspecified error
bchristi
parents:
diff
changeset
|
49 |
throw new RuntimeException("Expected IllegalStateException was not thrown."); |
df95bd1fd4b1
8187222: ClassLoader.getSystemClassLoader not clear if recursive initialization leads to ISE or unspecified error
bchristi
parents:
diff
changeset
|
50 |
} |
df95bd1fd4b1
8187222: ClassLoader.getSystemClassLoader not clear if recursive initialization leads to ISE or unspecified error
bchristi
parents:
diff
changeset
|
51 |
|
df95bd1fd4b1
8187222: ClassLoader.getSystemClassLoader not clear if recursive initialization leads to ISE or unspecified error
bchristi
parents:
diff
changeset
|
52 |
@Override |
df95bd1fd4b1
8187222: ClassLoader.getSystemClassLoader not clear if recursive initialization leads to ISE or unspecified error
bchristi
parents:
diff
changeset
|
53 |
public Class<?> loadClass(String name) throws ClassNotFoundException { |
df95bd1fd4b1
8187222: ClassLoader.getSystemClassLoader not clear if recursive initialization leads to ISE or unspecified error
bchristi
parents:
diff
changeset
|
54 |
return super.loadClass(name); |
df95bd1fd4b1
8187222: ClassLoader.getSystemClassLoader not clear if recursive initialization leads to ISE or unspecified error
bchristi
parents:
diff
changeset
|
55 |
} |
df95bd1fd4b1
8187222: ClassLoader.getSystemClassLoader not clear if recursive initialization leads to ISE or unspecified error
bchristi
parents:
diff
changeset
|
56 |
} |