19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
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 |
20 * or visit www.oracle.com if you need additional information or have any |
21 * questions. |
21 * questions. |
22 */ |
22 */ |
23 |
23 |
24 import java.lang.reflect.Module; |
|
25 import static jdk.test.lib.Asserts.*; |
24 import static jdk.test.lib.Asserts.*; |
26 |
25 |
27 /* |
26 /* |
28 * @test |
27 * @test |
29 * @modules java.base/jdk.internal.misc |
28 * @modules java.base/jdk.internal.misc |
30 * @library /test/lib .. |
29 * @library /test/lib .. |
31 * @compile p2/c2.java |
30 * @compile p2/c2.java |
32 * @compile p1/c1.java |
31 * @compile p1/c1.java |
33 * @build sun.hotspot.WhiteBox |
32 * @build sun.hotspot.WhiteBox |
34 * @compile/module=java.base java/lang/reflect/ModuleHelper.java |
33 * @compile/module=java.base java/lang/ModuleHelper.java |
35 * @run main ClassFileInstaller sun.hotspot.WhiteBox |
34 * @run main ClassFileInstaller sun.hotspot.WhiteBox |
36 * sun.hotspot.WhiteBox$WhiteBoxPermission |
35 * sun.hotspot.WhiteBox$WhiteBoxPermission |
37 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI AccessCheckUnnamed |
36 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI AccessCheckUnnamed |
38 */ |
37 */ |
39 |
38 |
42 // Test that a class in the unnamed module can not access a package in a |
41 // Test that a class in the unnamed module can not access a package in a |
43 // named module that has not been unqualifiedly exported. |
42 // named module that has not been unqualifiedly exported. |
44 public static void main(String args[]) throws Throwable { |
43 public static void main(String args[]) throws Throwable { |
45 Object m1x, m2x; |
44 Object m1x, m2x; |
46 |
45 |
47 // Get the java.lang.reflect.Module object for module java.base. |
46 // Get the java.lang.Module object for module java.base. |
48 Class jlObject = Class.forName("java.lang.Object"); |
47 Class jlObject = Class.forName("java.lang.Object"); |
49 Object jlObject_jlrM = jlObject.getModule(); |
48 Object jlObject_jlM = jlObject.getModule(); |
50 assertNotNull(jlObject_jlrM, "jlrModule object of java.lang.Object should not be null"); |
49 assertNotNull(jlObject_jlM, "jlModule object of java.lang.Object should not be null"); |
51 |
50 |
52 // Get the class loader for AccessCheckWorks and assume it's also used to |
51 // Get the class loader for AccessCheckWorks and assume it's also used to |
53 // load class p2.c2. |
52 // load class p2.c2. |
54 ClassLoader this_cldr = AccessCheckUnnamed.class.getClassLoader(); |
53 ClassLoader this_cldr = AccessCheckUnnamed.class.getClassLoader(); |
55 |
54 |
56 // Define a module for p2. |
55 // Define a module for p2. |
57 m2x = ModuleHelper.ModuleObject("module_two", this_cldr, new String[] { "p2" }); |
56 m2x = ModuleHelper.ModuleObject("module_two", this_cldr, new String[] { "p2" }); |
58 assertNotNull(m2x, "Module should not be null"); |
57 assertNotNull(m2x, "Module should not be null"); |
59 ModuleHelper.DefineModule(m2x, "9.0", "m2x/there", new String[] { "p2" }); |
58 ModuleHelper.DefineModule(m2x, "9.0", "m2x/there", new String[] { "p2" }); |
60 ModuleHelper.AddReadsModule(m2x, jlObject_jlrM); |
59 ModuleHelper.AddReadsModule(m2x, jlObject_jlM); |
61 |
60 |
62 // p1.c1's ctor tries to call a method in p2.c2. This should fail because |
61 // p1.c1's ctor tries to call a method in p2.c2. This should fail because |
63 // p1 is in the unnamed module and p2.c2 is not unqualifiedly exported. |
62 // p1 is in the unnamed module and p2.c2 is not unqualifiedly exported. |
64 Class p1_c1_class = Class.forName("p1.c1"); |
63 Class p1_c1_class = Class.forName("p1.c1"); |
65 try { |
64 try { |