author | rprotacio |
Mon, 24 Apr 2017 12:08:28 -0400 | |
changeset 46404 | ae62ba99a1a7 |
parent 44520 | 0553e129e0ec |
child 46458 | 3c12af929e7d |
permissions | -rw-r--r-- |
36508 | 1 |
/* |
43665
4bb003cad9b9
8173393: Module system implementation refresh (2/2017)
alanb
parents:
43446
diff
changeset
|
2 |
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved. |
36508 | 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 |
|
38152
80e5da81fb2c
8154258: [TESTBUG] Various serviceability tests fail compilation
dsamersoff
parents:
36508
diff
changeset
|
26 |
* @modules java.base/jdk.internal.misc |
40631
ed82623d7831
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
38152
diff
changeset
|
27 |
* @library /test/lib .. |
36508 | 28 |
* @build sun.hotspot.WhiteBox |
44520
0553e129e0ec
8177530: Module system implementation refresh (4/2017)
alanb
parents:
43665
diff
changeset
|
29 |
* @compile/module=java.base java/lang/ModuleHelper.java |
36508 | 30 |
* @run main ClassFileInstaller sun.hotspot.WhiteBox |
31 |
* sun.hotspot.WhiteBox$WhiteBoxPermission |
|
32 |
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI JVMAddModulePackage |
|
33 |
*/ |
|
34 |
||
35 |
import static jdk.test.lib.Asserts.*; |
|
42307
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40631
diff
changeset
|
36 |
import java.sql.Time; |
36508 | 37 |
|
38 |
public class JVMAddModulePackage { |
|
39 |
||
40 |
public static void main(String args[]) throws Throwable { |
|
41 |
MyClassLoader cl1 = new MyClassLoader(); |
|
42 |
MyClassLoader cl3 = new MyClassLoader(); |
|
43665
4bb003cad9b9
8173393: Module system implementation refresh (2/2017)
alanb
parents:
43446
diff
changeset
|
43 |
Object module_one, module_two, module_three; |
36508 | 44 |
boolean result; |
45 |
||
43665
4bb003cad9b9
8173393: Module system implementation refresh (2/2017)
alanb
parents:
43446
diff
changeset
|
46 |
module_one = ModuleHelper.ModuleObject("module_one", cl1, new String[] { "mypackage" }); |
4bb003cad9b9
8173393: Module system implementation refresh (2/2017)
alanb
parents:
43446
diff
changeset
|
47 |
assertNotNull(module_one, "Module should not be null"); |
46404
ae62ba99a1a7
8165896: Use "open" flag from JVM_DefineModule to export all module packages
rprotacio
parents:
44520
diff
changeset
|
48 |
ModuleHelper.DefineModule(module_one, false, "9.0", "module_one/here", new String[] { "mypackage" }); |
43665
4bb003cad9b9
8173393: Module system implementation refresh (2/2017)
alanb
parents:
43446
diff
changeset
|
49 |
module_two = ModuleHelper.ModuleObject("module_two", cl1, new String[] { "yourpackage" }); |
4bb003cad9b9
8173393: Module system implementation refresh (2/2017)
alanb
parents:
43446
diff
changeset
|
50 |
assertNotNull(module_two, "Module should not be null"); |
46404
ae62ba99a1a7
8165896: Use "open" flag from JVM_DefineModule to export all module packages
rprotacio
parents:
44520
diff
changeset
|
51 |
ModuleHelper.DefineModule(module_two, false, "9.0", "module_two/here", new String[] { "yourpackage" }); |
43665
4bb003cad9b9
8173393: Module system implementation refresh (2/2017)
alanb
parents:
43446
diff
changeset
|
52 |
module_three = ModuleHelper.ModuleObject("module_three", cl3, new String[] { "package/num3" }); |
4bb003cad9b9
8173393: Module system implementation refresh (2/2017)
alanb
parents:
43446
diff
changeset
|
53 |
assertNotNull(module_three, "Module should not be null"); |
46404
ae62ba99a1a7
8165896: Use "open" flag from JVM_DefineModule to export all module packages
rprotacio
parents:
44520
diff
changeset
|
54 |
ModuleHelper.DefineModule(module_three, false, "9.0", "module_three/here", new String[] { "package/num3" }); |
36508 | 55 |
|
56 |
// Simple call |
|
43665
4bb003cad9b9
8173393: Module system implementation refresh (2/2017)
alanb
parents:
43446
diff
changeset
|
57 |
ModuleHelper.AddModulePackage(module_one, "new_package"); |
36508 | 58 |
|
59 |
// Add a package and export it |
|
43665
4bb003cad9b9
8173393: Module system implementation refresh (2/2017)
alanb
parents:
43446
diff
changeset
|
60 |
ModuleHelper.AddModulePackage(module_one, "package/num3"); |
4bb003cad9b9
8173393: Module system implementation refresh (2/2017)
alanb
parents:
43446
diff
changeset
|
61 |
ModuleHelper.AddModuleExportsToAll(module_one, "package/num3"); |
36508 | 62 |
|
63 |
// Null module argument, expect an NPE |
|
64 |
try { |
|
65 |
ModuleHelper.AddModulePackage(null, "new_package"); |
|
66 |
throw new RuntimeException("Failed to get the expected NPE"); |
|
67 |
} catch(NullPointerException e) { |
|
68 |
// Expected |
|
69 |
} |
|
70 |
||
71 |
// Bad module argument, expect an IAE |
|
72 |
try { |
|
73 |
ModuleHelper.AddModulePackage(cl1, "new_package"); |
|
74 |
throw new RuntimeException("Failed to get the expected IAE"); |
|
75 |
} catch(IllegalArgumentException e) { |
|
76 |
// Expected |
|
77 |
} |
|
78 |
||
79 |
// Null package argument, expect an NPE |
|
80 |
try { |
|
43665
4bb003cad9b9
8173393: Module system implementation refresh (2/2017)
alanb
parents:
43446
diff
changeset
|
81 |
ModuleHelper.AddModulePackage(module_one, null); |
36508 | 82 |
throw new RuntimeException("Failed to get the expected NPE"); |
83 |
} catch(NullPointerException e) { |
|
84 |
// Expected |
|
85 |
} |
|
86 |
||
43446
4f9ac7ab99d9
8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents:
42307
diff
changeset
|
87 |
// Existing package, expect an ISE |
36508 | 88 |
try { |
43665
4bb003cad9b9
8173393: Module system implementation refresh (2/2017)
alanb
parents:
43446
diff
changeset
|
89 |
ModuleHelper.AddModulePackage(module_one, "yourpackage"); |
43446
4f9ac7ab99d9
8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents:
42307
diff
changeset
|
90 |
throw new RuntimeException("Failed to get the expected ISE"); |
4f9ac7ab99d9
8172288: Fix Jigsaw related module/package error messages and throw correct exceptions
hseigel
parents:
42307
diff
changeset
|
91 |
} catch(IllegalStateException e) { |
36508 | 92 |
// Expected |
93 |
} |
|
94 |
||
95 |
// Invalid package name, expect an IAE |
|
96 |
try { |
|
43665
4bb003cad9b9
8173393: Module system implementation refresh (2/2017)
alanb
parents:
43446
diff
changeset
|
97 |
ModuleHelper.AddModulePackage(module_one, "your.package"); |
36508 | 98 |
throw new RuntimeException("Failed to get the expected IAE"); |
99 |
} catch(IllegalArgumentException e) { |
|
100 |
// Expected |
|
101 |
} |
|
102 |
||
103 |
// Invalid package name, expect an IAE |
|
104 |
try { |
|
43665
4bb003cad9b9
8173393: Module system implementation refresh (2/2017)
alanb
parents:
43446
diff
changeset
|
105 |
ModuleHelper.AddModulePackage(module_one, ";your/package"); |
36508 | 106 |
throw new RuntimeException("Failed to get the expected IAE"); |
107 |
} catch(IllegalArgumentException e) { |
|
108 |
// Expected |
|
109 |
} |
|
110 |
||
111 |
// Invalid package name, expect an IAE |
|
112 |
try { |
|
43665
4bb003cad9b9
8173393: Module system implementation refresh (2/2017)
alanb
parents:
43446
diff
changeset
|
113 |
ModuleHelper.AddModulePackage(module_one, "7[743"); |
36508 | 114 |
throw new RuntimeException("Failed to get the expected IAE"); |
115 |
} catch(IllegalArgumentException e) { |
|
116 |
// Expected |
|
117 |
} |
|
118 |
||
119 |
// Empty package name, expect an IAE |
|
120 |
try { |
|
43665
4bb003cad9b9
8173393: Module system implementation refresh (2/2017)
alanb
parents:
43446
diff
changeset
|
121 |
ModuleHelper.AddModulePackage(module_one, ""); |
36508 | 122 |
throw new RuntimeException("Failed to get the expected IAE"); |
123 |
} catch(IllegalArgumentException e) { |
|
124 |
// Expected |
|
125 |
} |
|
126 |
||
42307
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40631
diff
changeset
|
127 |
// Add package named "java" to an module defined to a class loader other than the boot or platform loader. |
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40631
diff
changeset
|
128 |
try { |
43665
4bb003cad9b9
8173393: Module system implementation refresh (2/2017)
alanb
parents:
43446
diff
changeset
|
129 |
// module_one is defined to a MyClassLoader class loader. |
4bb003cad9b9
8173393: Module system implementation refresh (2/2017)
alanb
parents:
43446
diff
changeset
|
130 |
ModuleHelper.AddModulePackage(module_one, "java/foo"); |
42307
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40631
diff
changeset
|
131 |
throw new RuntimeException("Failed to get the expected IAE"); |
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40631
diff
changeset
|
132 |
} catch(IllegalArgumentException e) { |
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40631
diff
changeset
|
133 |
if (!e.getMessage().contains("prohibited package name")) { |
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40631
diff
changeset
|
134 |
throw new RuntimeException("Failed to get expected IAE message for prohibited package name: " + e.getMessage()); |
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40631
diff
changeset
|
135 |
} |
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40631
diff
changeset
|
136 |
} |
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40631
diff
changeset
|
137 |
|
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40631
diff
changeset
|
138 |
// Package "javabar" should be ok |
43665
4bb003cad9b9
8173393: Module system implementation refresh (2/2017)
alanb
parents:
43446
diff
changeset
|
139 |
ModuleHelper.AddModulePackage(module_one, "javabar"); |
42307
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40631
diff
changeset
|
140 |
|
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40631
diff
changeset
|
141 |
// Package named "java" defined to the boot class loader, should be ok |
43665
4bb003cad9b9
8173393: Module system implementation refresh (2/2017)
alanb
parents:
43446
diff
changeset
|
142 |
Object module_javabase = module_one.getClass().getModule(); |
42307
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40631
diff
changeset
|
143 |
ModuleHelper.AddModulePackage(module_javabase, "java/foo"); |
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40631
diff
changeset
|
144 |
|
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40631
diff
changeset
|
145 |
// Package named "java" defined to the platform class loader, should be ok |
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40631
diff
changeset
|
146 |
// The module java.sql is defined to the platform class loader. |
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40631
diff
changeset
|
147 |
java.sql.Time jst = new java.sql.Time(45000); // milliseconds |
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40631
diff
changeset
|
148 |
Object module_javasql = jst.getClass().getModule(); |
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40631
diff
changeset
|
149 |
ModuleHelper.AddModulePackage(module_javasql, "java/foo"); |
36508 | 150 |
} |
151 |
||
152 |
static class MyClassLoader extends ClassLoader { } |
|
153 |
} |
|
154 |