< prev index next >

test/runtime/modules/AccessCheckJavaBase.java

Print this page




  30  * @compile/module=java.base java/lang/reflect/ModuleHelper.java
  31  * @run main ClassFileInstaller sun.hotspot.WhiteBox
  32  *                              sun.hotspot.WhiteBox$WhiteBoxPermission
  33  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI AccessCheckJavaBase
  34  */
  35 
  36 import java.lang.reflect.Module;
  37 import static jdk.test.lib.Asserts.*;
  38 
  39 public class AccessCheckJavaBase {
  40 
  41     // Test that a class defined to module_two always can read java.base.
  42     public static void main(String args[]) throws Throwable {
  43         // Get the class loader for AccessCheckJavaBase and assume it's also used to
  44         // load class p2.c2.
  45         ClassLoader this_cldr = AccessCheckJavaBase.class.getClassLoader();
  46 
  47         // Define a module for p2.
  48         Object m2x = ModuleHelper.ModuleObject("module_two", this_cldr, new String[] { "p2" });
  49         assertNotNull(m2x, "Module should not be null");
  50         ModuleHelper.DefineModule(m2x, "9.0", "m2x/there", new String[] { "p2" });
  51 
  52         // p2.c2 can read its superclass java.lang.Object defined within java.base
  53         try {
  54             Class p2_c2_class = Class.forName("p2.c2");
  55         } catch (IllegalAccessError e) {
  56             throw new RuntimeException("Test Failed" + e.getMessage());
  57         }
  58     }
  59 }


  30  * @compile/module=java.base java/lang/reflect/ModuleHelper.java
  31  * @run main ClassFileInstaller sun.hotspot.WhiteBox
  32  *                              sun.hotspot.WhiteBox$WhiteBoxPermission
  33  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI AccessCheckJavaBase
  34  */
  35 
  36 import java.lang.reflect.Module;
  37 import static jdk.test.lib.Asserts.*;
  38 
  39 public class AccessCheckJavaBase {
  40 
  41     // Test that a class defined to module_two always can read java.base.
  42     public static void main(String args[]) throws Throwable {
  43         // Get the class loader for AccessCheckJavaBase and assume it's also used to
  44         // load class p2.c2.
  45         ClassLoader this_cldr = AccessCheckJavaBase.class.getClassLoader();
  46 
  47         // Define a module for p2.
  48         Object m2x = ModuleHelper.ModuleObject("module_two", this_cldr, new String[] { "p2" });
  49         assertNotNull(m2x, "Module should not be null");
  50         ModuleHelper.DefineModule(m2x, false, "9.0", "m2x/there", new String[] { "p2" });
  51 
  52         // p2.c2 can read its superclass java.lang.Object defined within java.base
  53         try {
  54             Class p2_c2_class = Class.forName("p2.c2");
  55         } catch (IllegalAccessError e) {
  56             throw new RuntimeException("Test Failed" + e.getMessage());
  57         }
  58     }
  59 }
< prev index next >