author | alanb |
Fri, 07 Apr 2017 08:04:46 +0000 | |
changeset 44520 | 0553e129e0ec |
parent 40631 | ed82623d7831 |
child 44993 | f61bcd80ec1f |
child 46404 | ae62ba99a1a7 |
permissions | -rw-r--r-- |
36508 | 1 |
/* |
44520
0553e129e0ec
8177530: Module system implementation refresh (4/2017)
alanb
parents:
40631
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:
40631
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 JVMAddModuleExports |
|
33 |
*/ |
|
34 |
||
35 |
import static jdk.test.lib.Asserts.*; |
|
36 |
||
37 |
public class JVMAddModuleExports { |
|
38 |
||
39 |
public static void main(String args[]) throws Throwable { |
|
40 |
MyClassLoader from_cl = new MyClassLoader(); |
|
41 |
MyClassLoader to_cl = new MyClassLoader(); |
|
42 |
Module from_module, to_module; |
|
43 |
||
44 |
from_module = ModuleHelper.ModuleObject("from_module", from_cl, new String[] { "mypackage", "this/package" }); |
|
45 |
assertNotNull(from_module, "Module should not be null"); |
|
46 |
ModuleHelper.DefineModule(from_module, "9.0", "from_module/here", new String[] { "mypackage", "this/package" }); |
|
47 |
to_module = ModuleHelper.ModuleObject("to_module", to_cl, new String[] { "yourpackage", "that/package" }); |
|
48 |
assertNotNull(to_module, "Module should not be null"); |
|
49 |
ModuleHelper.DefineModule(to_module, "9.0", "to_module/here", new String[] { "yourpackage", "that/package" }); |
|
50 |
||
51 |
// Null from_module argument, expect an NPE |
|
52 |
try { |
|
53 |
ModuleHelper.AddModuleExports((Module)null, "mypackage", to_module); |
|
54 |
throw new RuntimeException("Failed to get the expected NPE for null from_module"); |
|
55 |
} catch(NullPointerException e) { |
|
56 |
// Expected |
|
57 |
} |
|
58 |
||
59 |
// Null to_module argument, expect an NPE |
|
60 |
try { |
|
61 |
ModuleHelper.AddModuleExports(from_module, "mypackage", (Module)null); |
|
62 |
throw new RuntimeException("Failed to get the expected NPE for null to_module"); |
|
63 |
} catch(NullPointerException e) { |
|
64 |
// Expected |
|
65 |
} |
|
66 |
||
67 |
// Bad from_module argument, expect an IAE |
|
68 |
try { |
|
69 |
ModuleHelper.AddModuleExports(to_cl, "mypackage", to_module); |
|
70 |
throw new RuntimeException("Failed to get the expected IAE"); |
|
71 |
} catch(IllegalArgumentException e) { |
|
72 |
// Expected |
|
73 |
} |
|
74 |
||
75 |
// Null package argument, expect an NPE |
|
76 |
try { |
|
77 |
ModuleHelper.AddModuleExports(from_module, null, to_module); |
|
78 |
throw new RuntimeException("Failed to get the expected NPE"); |
|
79 |
} catch(NullPointerException e) { |
|
80 |
// Expected |
|
81 |
} |
|
82 |
||
83 |
// Bad to_module argument, expect an IAE |
|
84 |
try { |
|
85 |
ModuleHelper.AddModuleExports(from_module, "mypackage", from_cl); |
|
86 |
throw new RuntimeException("Failed to get the expected IAE"); |
|
87 |
} catch(IllegalArgumentException e) { |
|
88 |
// Expected |
|
89 |
} |
|
90 |
||
91 |
// Exporting a package to the same module |
|
92 |
ModuleHelper.AddModuleExports(from_module, "mypackage", from_module); |
|
93 |
||
94 |
// Export a package that does not exist to to_module |
|
95 |
try { |
|
96 |
ModuleHelper.AddModuleExports(from_module, "notmypackage", to_module); |
|
97 |
throw new RuntimeException("Failed to get the expected IAE"); |
|
98 |
} catch(IllegalArgumentException e) { |
|
99 |
// Expected |
|
100 |
} |
|
101 |
||
102 |
// Export a package, that is not in from_module, to to_module |
|
103 |
try { |
|
104 |
ModuleHelper.AddModuleExports(from_module, "yourpackage", to_module); |
|
105 |
throw new RuntimeException("Failed to get the expected IAE"); |
|
106 |
} catch(IllegalArgumentException e) { |
|
107 |
// Expected |
|
108 |
} |
|
109 |
||
110 |
// Export a package, that does not exist, to from_module |
|
111 |
try { |
|
112 |
ModuleHelper.AddModuleExports(from_module, "notmypackage", from_module); |
|
113 |
throw new RuntimeException("Failed to get the expected IAE"); |
|
114 |
} catch(IllegalArgumentException e) { |
|
115 |
// Expected |
|
116 |
} |
|
117 |
||
118 |
// Export a package, that is not in from_module, to from_module |
|
119 |
try { |
|
120 |
ModuleHelper.AddModuleExports(from_module, "that/package", from_module); |
|
121 |
throw new RuntimeException("Failed to get the expected IAE"); |
|
122 |
} catch(IllegalArgumentException e) { |
|
123 |
// Expected |
|
124 |
} |
|
125 |
||
126 |
// Export the same package twice to the same module |
|
127 |
ModuleHelper.AddModuleExports(from_module, "this/package", to_module); |
|
128 |
ModuleHelper.AddModuleExports(from_module, "this/package", to_module); |
|
129 |
||
130 |
// Export a package, using '.' instead of '/' |
|
131 |
try { |
|
132 |
ModuleHelper.AddModuleExports(from_module, "this.package", to_module); |
|
133 |
throw new RuntimeException("Failed to get the expected IAE"); |
|
134 |
} catch(IllegalArgumentException e) { |
|
135 |
// Expected |
|
136 |
} |
|
137 |
||
138 |
// Export a package to the unnamed module and then to a specific module. |
|
139 |
// The qualified export should be ignored. |
|
140 |
ModuleHelper.AddModuleExportsToAll(to_module, "that/package"); |
|
141 |
ModuleHelper.AddModuleExports(to_module, "that/package", from_module); |
|
142 |
} |
|
143 |
||
144 |
static class MyClassLoader extends ClassLoader { } |
|
145 |
} |