< prev index next >

test/runtime/modules/JVMAddModuleExports.java

Print this page




  26  * @modules java.base/jdk.internal.misc
  27  * @library /test/lib ..
  28  * @build sun.hotspot.WhiteBox
  29  * @compile/module=java.base java/lang/ModuleHelper.java
  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);




  26  * @modules java.base/jdk.internal.misc
  27  * @library /test/lib ..
  28  * @build sun.hotspot.WhiteBox
  29  * @compile/module=java.base java/lang/ModuleHelper.java
  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, false, "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, false, "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);


< prev index next >