author | mchung |
Tue, 09 May 2017 10:34:13 -0700 | |
changeset 45031 | cd369ee4d4bc |
permissions | -rw-r--r-- |
45031
cd369ee4d4bc
8179950: Custom system class loader using Enum.valueOf in its initialization triggers java.lang.InternalError
mchung
parents:
diff
changeset
|
1 |
/* |
cd369ee4d4bc
8179950: Custom system class loader using Enum.valueOf in its initialization triggers java.lang.InternalError
mchung
parents:
diff
changeset
|
2 |
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. |
cd369ee4d4bc
8179950: Custom system class loader using Enum.valueOf in its initialization triggers java.lang.InternalError
mchung
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
cd369ee4d4bc
8179950: Custom system class loader using Enum.valueOf in its initialization triggers java.lang.InternalError
mchung
parents:
diff
changeset
|
4 |
* |
cd369ee4d4bc
8179950: Custom system class loader using Enum.valueOf in its initialization triggers java.lang.InternalError
mchung
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
cd369ee4d4bc
8179950: Custom system class loader using Enum.valueOf in its initialization triggers java.lang.InternalError
mchung
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
cd369ee4d4bc
8179950: Custom system class loader using Enum.valueOf in its initialization triggers java.lang.InternalError
mchung
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
cd369ee4d4bc
8179950: Custom system class loader using Enum.valueOf in its initialization triggers java.lang.InternalError
mchung
parents:
diff
changeset
|
8 |
* |
cd369ee4d4bc
8179950: Custom system class loader using Enum.valueOf in its initialization triggers java.lang.InternalError
mchung
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
cd369ee4d4bc
8179950: Custom system class loader using Enum.valueOf in its initialization triggers java.lang.InternalError
mchung
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
cd369ee4d4bc
8179950: Custom system class loader using Enum.valueOf in its initialization triggers java.lang.InternalError
mchung
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
cd369ee4d4bc
8179950: Custom system class loader using Enum.valueOf in its initialization triggers java.lang.InternalError
mchung
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
cd369ee4d4bc
8179950: Custom system class loader using Enum.valueOf in its initialization triggers java.lang.InternalError
mchung
parents:
diff
changeset
|
13 |
* accompanied this code). |
cd369ee4d4bc
8179950: Custom system class loader using Enum.valueOf in its initialization triggers java.lang.InternalError
mchung
parents:
diff
changeset
|
14 |
* |
cd369ee4d4bc
8179950: Custom system class loader using Enum.valueOf in its initialization triggers java.lang.InternalError
mchung
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
cd369ee4d4bc
8179950: Custom system class loader using Enum.valueOf in its initialization triggers java.lang.InternalError
mchung
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
cd369ee4d4bc
8179950: Custom system class loader using Enum.valueOf in its initialization triggers java.lang.InternalError
mchung
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
cd369ee4d4bc
8179950: Custom system class loader using Enum.valueOf in its initialization triggers java.lang.InternalError
mchung
parents:
diff
changeset
|
18 |
* |
cd369ee4d4bc
8179950: Custom system class loader using Enum.valueOf in its initialization triggers java.lang.InternalError
mchung
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
cd369ee4d4bc
8179950: Custom system class loader using Enum.valueOf in its initialization triggers java.lang.InternalError
mchung
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
cd369ee4d4bc
8179950: Custom system class loader using Enum.valueOf in its initialization triggers java.lang.InternalError
mchung
parents:
diff
changeset
|
21 |
* questions. |
cd369ee4d4bc
8179950: Custom system class loader using Enum.valueOf in its initialization triggers java.lang.InternalError
mchung
parents:
diff
changeset
|
22 |
*/ |
cd369ee4d4bc
8179950: Custom system class loader using Enum.valueOf in its initialization triggers java.lang.InternalError
mchung
parents:
diff
changeset
|
23 |
|
cd369ee4d4bc
8179950: Custom system class loader using Enum.valueOf in its initialization triggers java.lang.InternalError
mchung
parents:
diff
changeset
|
24 |
/* |
cd369ee4d4bc
8179950: Custom system class loader using Enum.valueOf in its initialization triggers java.lang.InternalError
mchung
parents:
diff
changeset
|
25 |
* @test |
cd369ee4d4bc
8179950: Custom system class loader using Enum.valueOf in its initialization triggers java.lang.InternalError
mchung
parents:
diff
changeset
|
26 |
* @bug 8179950 |
cd369ee4d4bc
8179950: Custom system class loader using Enum.valueOf in its initialization triggers java.lang.InternalError
mchung
parents:
diff
changeset
|
27 |
* @build CustomLoader InitSystemLoaderTest |
cd369ee4d4bc
8179950: Custom system class loader using Enum.valueOf in its initialization triggers java.lang.InternalError
mchung
parents:
diff
changeset
|
28 |
* @run main/othervm -Djava.system.class.loader=CustomLoader InitSystemLoaderTest |
cd369ee4d4bc
8179950: Custom system class loader using Enum.valueOf in its initialization triggers java.lang.InternalError
mchung
parents:
diff
changeset
|
29 |
* @summary Test custom system loader initialization and verify their ancestors |
cd369ee4d4bc
8179950: Custom system class loader using Enum.valueOf in its initialization triggers java.lang.InternalError
mchung
parents:
diff
changeset
|
30 |
*/ |
cd369ee4d4bc
8179950: Custom system class loader using Enum.valueOf in its initialization triggers java.lang.InternalError
mchung
parents:
diff
changeset
|
31 |
|
cd369ee4d4bc
8179950: Custom system class loader using Enum.valueOf in its initialization triggers java.lang.InternalError
mchung
parents:
diff
changeset
|
32 |
public class InitSystemLoaderTest { |
cd369ee4d4bc
8179950: Custom system class loader using Enum.valueOf in its initialization triggers java.lang.InternalError
mchung
parents:
diff
changeset
|
33 |
public static void main(String... args) { |
cd369ee4d4bc
8179950: Custom system class loader using Enum.valueOf in its initialization triggers java.lang.InternalError
mchung
parents:
diff
changeset
|
34 |
// check that system class loader is the custom loader |
cd369ee4d4bc
8179950: Custom system class loader using Enum.valueOf in its initialization triggers java.lang.InternalError
mchung
parents:
diff
changeset
|
35 |
ClassLoader loader = ClassLoader.getSystemClassLoader(); |
cd369ee4d4bc
8179950: Custom system class loader using Enum.valueOf in its initialization triggers java.lang.InternalError
mchung
parents:
diff
changeset
|
36 |
if (loader != CustomLoader.INSTANCE) { |
cd369ee4d4bc
8179950: Custom system class loader using Enum.valueOf in its initialization triggers java.lang.InternalError
mchung
parents:
diff
changeset
|
37 |
throw new RuntimeException("Expected custom loader: " |
cd369ee4d4bc
8179950: Custom system class loader using Enum.valueOf in its initialization triggers java.lang.InternalError
mchung
parents:
diff
changeset
|
38 |
+ CustomLoader.INSTANCE + " got: " + loader); |
cd369ee4d4bc
8179950: Custom system class loader using Enum.valueOf in its initialization triggers java.lang.InternalError
mchung
parents:
diff
changeset
|
39 |
} |
cd369ee4d4bc
8179950: Custom system class loader using Enum.valueOf in its initialization triggers java.lang.InternalError
mchung
parents:
diff
changeset
|
40 |
|
cd369ee4d4bc
8179950: Custom system class loader using Enum.valueOf in its initialization triggers java.lang.InternalError
mchung
parents:
diff
changeset
|
41 |
// parent of the custom loader should be builtin system class loader |
cd369ee4d4bc
8179950: Custom system class loader using Enum.valueOf in its initialization triggers java.lang.InternalError
mchung
parents:
diff
changeset
|
42 |
ClassLoader builtinSystemLoader = loader.getParent(); |
cd369ee4d4bc
8179950: Custom system class loader using Enum.valueOf in its initialization triggers java.lang.InternalError
mchung
parents:
diff
changeset
|
43 |
ClassLoader grandparent = builtinSystemLoader.getParent(); |
cd369ee4d4bc
8179950: Custom system class loader using Enum.valueOf in its initialization triggers java.lang.InternalError
mchung
parents:
diff
changeset
|
44 |
if (grandparent != ClassLoader.getPlatformClassLoader()) { |
cd369ee4d4bc
8179950: Custom system class loader using Enum.valueOf in its initialization triggers java.lang.InternalError
mchung
parents:
diff
changeset
|
45 |
throw new RuntimeException("Expected class loader ancestor: " |
cd369ee4d4bc
8179950: Custom system class loader using Enum.valueOf in its initialization triggers java.lang.InternalError
mchung
parents:
diff
changeset
|
46 |
+ ClassLoader.getPlatformClassLoader() + " got: " + grandparent); |
cd369ee4d4bc
8179950: Custom system class loader using Enum.valueOf in its initialization triggers java.lang.InternalError
mchung
parents:
diff
changeset
|
47 |
} |
cd369ee4d4bc
8179950: Custom system class loader using Enum.valueOf in its initialization triggers java.lang.InternalError
mchung
parents:
diff
changeset
|
48 |
} |
cd369ee4d4bc
8179950: Custom system class loader using Enum.valueOf in its initialization triggers java.lang.InternalError
mchung
parents:
diff
changeset
|
49 |
} |