hotspot/test/runtime/modules/AccessCheck/Umod_PkgNotExp.java
changeset 44520 0553e129e0ec
parent 43665 4bb003cad9b9
equal deleted inserted replaced
44471:7e8e5ceecf99 44520:0553e129e0ec
    35  * @run main/othervm -Xbootclasspath/a:. Umod_PkgNotExp
    35  * @run main/othervm -Xbootclasspath/a:. Umod_PkgNotExp
    36  */
    36  */
    37 
    37 
    38 import static jdk.test.lib.Asserts.*;
    38 import static jdk.test.lib.Asserts.*;
    39 
    39 
    40 import java.lang.reflect.Layer;
       
    41 import java.lang.module.Configuration;
    40 import java.lang.module.Configuration;
    42 import java.lang.module.ModuleDescriptor;
    41 import java.lang.module.ModuleDescriptor;
    43 import java.lang.module.ModuleFinder;
    42 import java.lang.module.ModuleFinder;
    44 import java.util.HashMap;
    43 import java.util.HashMap;
    45 import java.util.Map;
    44 import java.util.Map;
    55 // class p1.c1 defined in an unnamed module tries to access p2.c2 defined in m2x
    54 // class p1.c1 defined in an unnamed module tries to access p2.c2 defined in m2x
    56 // Access denied since p2 is not exported.
    55 // Access denied since p2 is not exported.
    57 //
    56 //
    58 public class Umod_PkgNotExp {
    57 public class Umod_PkgNotExp {
    59 
    58 
    60     // Create a Layer over the boot layer.
    59     // Create a layer over the boot layer.
    61     // Define modules within this layer to test access between
    60     // Define modules within this layer to test access between
    62     // publically defined classes within packages of those modules.
    61     // publically defined classes within packages of those modules.
    63     public void createLayerOnBoot() throws Throwable {
    62     public void createLayerOnBoot() throws Throwable {
    64 
    63 
    65         // Define module:     m1x
    64         // Define module:     m1x
    84 
    83 
    85         // Set up a ModuleFinder containing all modules for this layer.
    84         // Set up a ModuleFinder containing all modules for this layer.
    86         ModuleFinder finder = ModuleLibrary.of(descriptor_m1x, descriptor_m2x);
    85         ModuleFinder finder = ModuleLibrary.of(descriptor_m1x, descriptor_m2x);
    87 
    86 
    88         // Resolves "m1x"
    87         // Resolves "m1x"
    89         Configuration cf = Layer.boot()
    88         Configuration cf = ModuleLayer.boot()
    90                 .configuration()
    89                 .configuration()
    91                 .resolve(finder, ModuleFinder.of(), Set.of("m1x"));
    90                 .resolve(finder, ModuleFinder.of(), Set.of("m1x"));
    92 
    91 
    93         // map each module to the same class loader for this test
    92         // map each module to the same class loader for this test
    94         Map<String, ClassLoader> map = new HashMap<>();
    93         Map<String, ClassLoader> map = new HashMap<>();
    95         map.put("m1x", MySameClassLoader.loader1);
    94         map.put("m1x", MySameClassLoader.loader1);
    96         map.put("m2x", MySameClassLoader.loader1);
    95         map.put("m2x", MySameClassLoader.loader1);
    97 
    96 
    98         // Create Layer that contains m1x and m2x
    97         // Create layer that contains m1x and m2x
    99         Layer layer = Layer.boot().defineModules(cf, map::get);
    98         ModuleLayer layer = ModuleLayer.boot().defineModules(cf, map::get);
   100 
    99 
   101         assertTrue(layer.findLoader("m1x") == MySameClassLoader.loader1);
   100         assertTrue(layer.findLoader("m1x") == MySameClassLoader.loader1);
   102         assertTrue(layer.findLoader("m2x") == MySameClassLoader.loader1);
   101         assertTrue(layer.findLoader("m2x") == MySameClassLoader.loader1);
   103         assertTrue(layer.findLoader("java.base") == null);
   102         assertTrue(layer.findLoader("java.base") == null);
   104 
   103