mirror of
https://github.com/openjdk/jdk.git
synced 2026-03-16 02:43:20 +00:00
8173393: Module system implementation refresh (2/2017)
Co-authored-by: George Triantafillou <george.triantafillou@oracle.com> Reviewed-by: lfoltan, acorn, mchung
This commit is contained in:
parent
27dc8df66b
commit
9db79d57c8
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -1208,9 +1208,10 @@ JVM_ENTRY(jobject, MHN_resolve_Mem(JNIEnv *env, jobject igcls, jobject mname_jh,
|
||||
if (reference_klass != NULL && reference_klass->is_instance_klass()) {
|
||||
// Emulate LinkResolver::check_klass_accessability.
|
||||
Klass* caller = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(caller_jh));
|
||||
if (Reflection::verify_class_access(caller,
|
||||
reference_klass,
|
||||
true) != Reflection::ACCESS_OK) {
|
||||
if (caller != SystemDictionary::Object_klass()
|
||||
&& Reflection::verify_class_access(caller,
|
||||
reference_klass,
|
||||
true) != Reflection::ACCESS_OK) {
|
||||
THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), reference_klass->external_name());
|
||||
}
|
||||
}
|
||||
|
||||
@ -73,6 +73,7 @@ runtime/SharedArchiveFile/DefaultUseWithClient.java 8154204 generic-all
|
||||
|
||||
serviceability/jdwp/AllModulesCommandTest.java 8168478 generic-all
|
||||
serviceability/sa/sadebugd/SADebugDTest.java 8163805 generic-all
|
||||
serviceability/jvmti/ModuleAwareAgents/ClassFileLoadHook/MAAClassFileLoadHook.java 8173936 generic-all
|
||||
|
||||
#############################################################################
|
||||
|
||||
|
||||
@ -68,7 +68,7 @@ public class AccessExportTwice {
|
||||
// Packages: none
|
||||
// Packages exported: none
|
||||
ModuleDescriptor descriptor_first_mod =
|
||||
ModuleDescriptor.module("first_mod")
|
||||
ModuleDescriptor.newModule("first_mod")
|
||||
.requires("java.base")
|
||||
.requires("second_mod")
|
||||
.build();
|
||||
@ -78,7 +78,7 @@ public class AccessExportTwice {
|
||||
// Packages: p2
|
||||
// Packages exported: p2 is exported to first_mod
|
||||
ModuleDescriptor descriptor_second_mod =
|
||||
ModuleDescriptor.module("second_mod")
|
||||
ModuleDescriptor.newModule("second_mod")
|
||||
.requires("java.base")
|
||||
.exports("p2", Set.of("first_mod"))
|
||||
.build();
|
||||
@ -89,7 +89,7 @@ public class AccessExportTwice {
|
||||
// Resolves "first_mod"
|
||||
Configuration cf = Layer.boot()
|
||||
.configuration()
|
||||
.resolveRequires(finder, ModuleFinder.of(), Set.of("first_mod"));
|
||||
.resolve(finder, ModuleFinder.of(), Set.of("first_mod"));
|
||||
|
||||
// Map each module to the same class loader
|
||||
Map<String, ClassLoader> map = new HashMap<>();
|
||||
|
||||
@ -66,9 +66,9 @@ public class AccessReadTwice {
|
||||
// Packages: p1, p4
|
||||
// Packages exported: none
|
||||
ModuleDescriptor descriptor_first_mod =
|
||||
ModuleDescriptor.module("first_mod")
|
||||
ModuleDescriptor.newModule("first_mod")
|
||||
.requires("java.base")
|
||||
.contains(Set.of("p1", "p4"))
|
||||
.packages(Set.of("p1", "p4"))
|
||||
.build();
|
||||
|
||||
// Define module: second_mod
|
||||
@ -76,7 +76,7 @@ public class AccessReadTwice {
|
||||
// Packages: p2
|
||||
// Packages exported: p2 is exported to first_mod
|
||||
ModuleDescriptor descriptor_second_mod =
|
||||
ModuleDescriptor.module("second_mod")
|
||||
ModuleDescriptor.newModule("second_mod")
|
||||
.requires("java.base")
|
||||
.exports("p2", Set.of("first_mod"))
|
||||
.build();
|
||||
@ -87,7 +87,7 @@ public class AccessReadTwice {
|
||||
// Resolves "first_mod" and "second_mod"
|
||||
Configuration cf = Layer.boot()
|
||||
.configuration()
|
||||
.resolveRequires(finder, ModuleFinder.of(), Set.of("first_mod", "second_mod"));
|
||||
.resolve(finder, ModuleFinder.of(), Set.of("first_mod", "second_mod"));
|
||||
|
||||
// Map each module to this class loader
|
||||
Map<String, ClassLoader> map = new HashMap<>();
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -25,8 +25,8 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Test that if module m1 can not read module m2, then class p1.c1
|
||||
* in module m1 can not access p2.c2 in module m2.
|
||||
* @summary Test that if module m1x can not read module m2x, then class p1.c1
|
||||
* in module m1x can not access p2.c2 in module m2x.
|
||||
* @modules java.base/jdk.internal.misc
|
||||
* @library /test/lib
|
||||
* @compile myloaders/MySameClassLoader.java
|
||||
@ -47,15 +47,15 @@ import java.util.Set;
|
||||
import myloaders.MySameClassLoader;
|
||||
|
||||
//
|
||||
// ClassLoader1 --> defines m1 --> packages p1
|
||||
// defines m2 --> packages p2
|
||||
// defines m3 --> packages p3
|
||||
// ClassLoader1 --> defines m1x --> packages p1
|
||||
// defines m2x --> packages p2
|
||||
// defines m3x --> packages p3
|
||||
//
|
||||
// m1 can not read m2
|
||||
// package p2 in m2 is exported to m1
|
||||
// m1x can not read m2x
|
||||
// package p2 in m2x is exported to m1x
|
||||
//
|
||||
// class p1.c1 defined in m1 tries to access p2.c2 defined in m2.
|
||||
// Access denied since m1 can not read m2.
|
||||
// class p1.c1 defined in m1x tries to access p2.c2 defined in m2x.
|
||||
// Access denied since m1x can not read m2x.
|
||||
//
|
||||
public class CheckRead {
|
||||
|
||||
@ -64,65 +64,65 @@ public class CheckRead {
|
||||
// publicly defined classes within packages of those modules.
|
||||
public void createLayerOnBoot() throws Throwable {
|
||||
|
||||
// Define module: m1
|
||||
// Can read: java.base, m3
|
||||
// Define module: m1x
|
||||
// Can read: java.base, m3x
|
||||
// Packages: p1
|
||||
// Packages exported: p1 is exported unqualifiedly
|
||||
ModuleDescriptor descriptor_m1 =
|
||||
ModuleDescriptor.module("m1")
|
||||
ModuleDescriptor descriptor_m1x =
|
||||
ModuleDescriptor.newModule("m1x")
|
||||
.requires("java.base")
|
||||
.requires("m3")
|
||||
.requires("m3x")
|
||||
.exports("p1")
|
||||
.build();
|
||||
|
||||
// Define module: m2
|
||||
// Define module: m2x
|
||||
// Can read: java.base
|
||||
// Packages: p2
|
||||
// Packages exported: p2 is exported to m1
|
||||
ModuleDescriptor descriptor_m2 =
|
||||
ModuleDescriptor.module("m2")
|
||||
// Packages exported: p2 is exported to m1x
|
||||
ModuleDescriptor descriptor_m2x =
|
||||
ModuleDescriptor.newModule("m2x")
|
||||
.requires("java.base")
|
||||
.exports("p2", Set.of("m1"))
|
||||
.exports("p2", Set.of("m1x"))
|
||||
.build();
|
||||
|
||||
// Define module: m3
|
||||
// Can read: java.base, m2
|
||||
// Define module: m3x
|
||||
// Can read: java.base, m2x
|
||||
// Packages: p3
|
||||
// Packages exported: none
|
||||
ModuleDescriptor descriptor_m3 =
|
||||
ModuleDescriptor.module("m3")
|
||||
ModuleDescriptor descriptor_m3x =
|
||||
ModuleDescriptor.newModule("m3x")
|
||||
.requires("java.base")
|
||||
.requires("m2")
|
||||
.contains("p3")
|
||||
.requires("m2x")
|
||||
.packages(Set.of("p3"))
|
||||
.build();
|
||||
|
||||
// Set up a ModuleFinder containing all modules for this layer.
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1, descriptor_m2, descriptor_m3);
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1x, descriptor_m2x, descriptor_m3x);
|
||||
|
||||
// Resolves "m1"
|
||||
// Resolves "m1x"
|
||||
Configuration cf = Layer.boot()
|
||||
.configuration()
|
||||
.resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
|
||||
.resolve(finder, ModuleFinder.of(), Set.of("m1x"));
|
||||
|
||||
// map each module to differing class loaders for this test
|
||||
Map<String, ClassLoader> map = new HashMap<>();
|
||||
map.put("m1", MySameClassLoader.loader1);
|
||||
map.put("m2", MySameClassLoader.loader1);
|
||||
map.put("m3", MySameClassLoader.loader1);
|
||||
map.put("m1x", MySameClassLoader.loader1);
|
||||
map.put("m2x", MySameClassLoader.loader1);
|
||||
map.put("m3x", MySameClassLoader.loader1);
|
||||
|
||||
// Create Layer that contains m1, m2 and m3
|
||||
// Create Layer that contains m1x, m2x and m3x
|
||||
Layer layer = Layer.boot().defineModules(cf, map::get);
|
||||
|
||||
assertTrue(layer.findLoader("m1") == MySameClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m2") == MySameClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m3") == MySameClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m1x") == MySameClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m2x") == MySameClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m3x") == MySameClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("java.base") == null);
|
||||
|
||||
// now use the same loader to load class p1.c1
|
||||
Class p1_c1_class = MySameClassLoader.loader1.loadClass("p1.c1");
|
||||
try {
|
||||
p1_c1_class.newInstance();
|
||||
throw new RuntimeException("Failed to get IAE (p2 in m2 is exported to m1 but m2 is not readable from m1)");
|
||||
throw new RuntimeException("Failed to get IAE (p2 in m2x is exported to m1x but m2x is not readable from m1x)");
|
||||
} catch (IllegalAccessError e) {
|
||||
System.out.println(e.getMessage());
|
||||
if (!e.getMessage().contains("cannot access")) {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -25,8 +25,8 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Test that if module m1 can not read module m2, then class p1.c1
|
||||
* in module m1 can not access p2.c2 in module m2.
|
||||
* @summary Test that if module m1x can not read module m2x, then class p1.c1
|
||||
* in module m1x can not access p2.c2 in module m2x.
|
||||
* @modules java.base/jdk.internal.misc
|
||||
* @library /test/lib
|
||||
* @compile myloaders/MyDiffClassLoader.java
|
||||
@ -47,15 +47,15 @@ import java.util.Set;
|
||||
import myloaders.MyDiffClassLoader;
|
||||
|
||||
//
|
||||
// ClassLoader1 --> defines m1 --> packages p1
|
||||
// ClassLoader2 --> defines m2 --> packages p2
|
||||
// defines m3 --> packages p3
|
||||
// ClassLoader1 --> defines m1x --> packages p1
|
||||
// ClassLoader2 --> defines m2x --> packages p2
|
||||
// defines m3x --> packages p3
|
||||
//
|
||||
// m1 can not read m2
|
||||
// package p2 in m2 is exported to m1
|
||||
// m1x can not read m2x
|
||||
// package p2 in m2x is exported to m1x
|
||||
//
|
||||
// class p1.c1 defined in m1 tries to access p2.c2 defined in m2.
|
||||
// Access denied since m1 can not read m2.
|
||||
// class p1.c1 defined in m1x tries to access p2.c2 defined in m2x.
|
||||
// Access denied since m1x can not read m2x.
|
||||
//
|
||||
public class DiffCL_CheckRead {
|
||||
|
||||
@ -64,65 +64,65 @@ public class DiffCL_CheckRead {
|
||||
// publicly defined classes within packages of those modules.
|
||||
public void createLayerOnBoot() throws Throwable {
|
||||
|
||||
// Define module: m1
|
||||
// Can read: java.base, m3
|
||||
// Define module: m1x
|
||||
// Can read: java.base, m3x
|
||||
// Packages: p1
|
||||
// Packages exported: p1 is exported unqualifiedly
|
||||
ModuleDescriptor descriptor_m1 =
|
||||
ModuleDescriptor.module("m1")
|
||||
ModuleDescriptor descriptor_m1x =
|
||||
ModuleDescriptor.newModule("m1x")
|
||||
.requires("java.base")
|
||||
.requires("m3")
|
||||
.requires("m3x")
|
||||
.exports("p1")
|
||||
.build();
|
||||
|
||||
// Define module: m2
|
||||
// Define module: m2x
|
||||
// Can read: java.base
|
||||
// Packages: p2
|
||||
// Packages exported: p2 is exported to m1
|
||||
ModuleDescriptor descriptor_m2 =
|
||||
ModuleDescriptor.module("m2")
|
||||
// Packages exported: p2 is exported to m1x
|
||||
ModuleDescriptor descriptor_m2x =
|
||||
ModuleDescriptor.newModule("m2x")
|
||||
.requires("java.base")
|
||||
.exports("p2", Set.of("m1"))
|
||||
.exports("p2", Set.of("m1x"))
|
||||
.build();
|
||||
|
||||
// Define module: m3
|
||||
// Can read: java.base, m2
|
||||
// Define module: m3x
|
||||
// Can read: java.base, m2x
|
||||
// Packages: p3
|
||||
// Packages exported: none
|
||||
ModuleDescriptor descriptor_m3 =
|
||||
ModuleDescriptor.module("m3")
|
||||
ModuleDescriptor descriptor_m3x =
|
||||
ModuleDescriptor.newModule("m3x")
|
||||
.requires("java.base")
|
||||
.requires("m2")
|
||||
.contains("p3")
|
||||
.requires("m2x")
|
||||
.packages(Set.of("p3"))
|
||||
.build();
|
||||
|
||||
// Set up a ModuleFinder containing all modules for this layer.
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1, descriptor_m2, descriptor_m3);
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1x, descriptor_m2x, descriptor_m3x);
|
||||
|
||||
// Resolves "m1"
|
||||
// Resolves "m1x"
|
||||
Configuration cf = Layer.boot()
|
||||
.configuration()
|
||||
.resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
|
||||
.resolve(finder, ModuleFinder.of(), Set.of("m1x"));
|
||||
|
||||
// map each module to differing class loaders for this test
|
||||
Map<String, ClassLoader> map = new HashMap<>();
|
||||
map.put("m1", MyDiffClassLoader.loader1);
|
||||
map.put("m2", MyDiffClassLoader.loader2);
|
||||
map.put("m3", MyDiffClassLoader.loader2);
|
||||
map.put("m1x", MyDiffClassLoader.loader1);
|
||||
map.put("m2x", MyDiffClassLoader.loader2);
|
||||
map.put("m3x", MyDiffClassLoader.loader2);
|
||||
|
||||
// Create Layer that contains m1, m2 and m3
|
||||
// Create Layer that contains m1x, m2x and m3x
|
||||
Layer layer = Layer.boot().defineModules(cf, map::get);
|
||||
|
||||
assertTrue(layer.findLoader("m1") == MyDiffClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m2") == MyDiffClassLoader.loader2);
|
||||
assertTrue(layer.findLoader("m3") == MyDiffClassLoader.loader2);
|
||||
assertTrue(layer.findLoader("m1x") == MyDiffClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m2x") == MyDiffClassLoader.loader2);
|
||||
assertTrue(layer.findLoader("m3x") == MyDiffClassLoader.loader2);
|
||||
assertTrue(layer.findLoader("java.base") == null);
|
||||
|
||||
// now use the same loader to load class p1.c1
|
||||
Class p1_c1_class = MyDiffClassLoader.loader1.loadClass("p1.c1");
|
||||
try {
|
||||
p1_c1_class.newInstance();
|
||||
throw new RuntimeException("Failed to get IAE (p2 in m2 is exported to m1 but m2 is not readable from m1)");
|
||||
throw new RuntimeException("Failed to get IAE (p2 in m2x is exported to m1x but m2x is not readable from m1x)");
|
||||
} catch (IllegalAccessError e) {
|
||||
System.out.println(e.getMessage());
|
||||
if (!e.getMessage().contains("cannot access")) {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -25,9 +25,9 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Test that if module m1 can read module m2, but package p2 in m2
|
||||
* is exported specifically to module m3, then class p1.c1 in m1 can not
|
||||
* access p2.c2 in m2.
|
||||
* @summary Test that if module m1x can read module m2x, but package p2 in m2x
|
||||
* is exported specifically to module m3x, then class p1.c1 in m1x can not
|
||||
* access p2.c2 in m2x.
|
||||
* @modules java.base/jdk.internal.misc
|
||||
* @library /test/lib
|
||||
* @compile myloaders/MyDiffClassLoader.java
|
||||
@ -48,15 +48,15 @@ import java.util.Set;
|
||||
import myloaders.MyDiffClassLoader;
|
||||
|
||||
//
|
||||
// ClassLoader1 --> defines m1 --> packages p1
|
||||
// ClassLoader2 --> defines m2 --> packages p2
|
||||
// defines m3 --> packages p3
|
||||
// ClassLoader1 --> defines m1x --> packages p1
|
||||
// ClassLoader2 --> defines m2x --> packages p2
|
||||
// defines m3x --> packages p3
|
||||
//
|
||||
// m1 can read m2
|
||||
// package p2 in m2 is exported to m3
|
||||
// m1x can read m2x
|
||||
// package p2 in m2x is exported to m3x
|
||||
//
|
||||
// class p1.c1 defined in m1 tries to access p2.c2 defined in m2
|
||||
// Access denied since although m1 can read m2, p2 is exported only to m3.
|
||||
// class p1.c1 defined in m1x tries to access p2.c2 defined in m2x
|
||||
// Access denied since although m1x can read m2x, p2 is exported only to m3x.
|
||||
//
|
||||
public class DiffCL_ExpQualOther {
|
||||
|
||||
@ -65,66 +65,66 @@ public class DiffCL_ExpQualOther {
|
||||
// publically defined classes within packages of those modules.
|
||||
public void createLayerOnBoot() throws Throwable {
|
||||
|
||||
// Define module: m1
|
||||
// Can read: java.base, m2, m3
|
||||
// Define module: m1x
|
||||
// Can read: java.base, m2x, m3x
|
||||
// Packages: p1
|
||||
// Packages exported: p1 is exported unqualifiedly
|
||||
ModuleDescriptor descriptor_m1 =
|
||||
ModuleDescriptor.module("m1")
|
||||
ModuleDescriptor descriptor_m1x =
|
||||
ModuleDescriptor.newModule("m1x")
|
||||
.requires("java.base")
|
||||
.requires("m2")
|
||||
.requires("m3")
|
||||
.requires("m2x")
|
||||
.requires("m3x")
|
||||
.exports("p1")
|
||||
.build();
|
||||
|
||||
// Define module: m2
|
||||
// Can read: java.base, m3
|
||||
// Define module: m2x
|
||||
// Can read: java.base, m3x
|
||||
// Packages: p2
|
||||
// Packages exported: p2 is exported to m3
|
||||
ModuleDescriptor descriptor_m2 =
|
||||
ModuleDescriptor.module("m2")
|
||||
// Packages exported: p2 is exported to m3x
|
||||
ModuleDescriptor descriptor_m2x =
|
||||
ModuleDescriptor.newModule("m2x")
|
||||
.requires("java.base")
|
||||
.exports("p2", Set.of("m3"))
|
||||
.exports("p2", Set.of("m3x"))
|
||||
.build();
|
||||
|
||||
// Define module: m3
|
||||
// Can read: java.base, m2
|
||||
// Define module: m3x
|
||||
// Can read: java.base, m2x
|
||||
// Packages: p3
|
||||
// Packages exported: none
|
||||
ModuleDescriptor descriptor_m3 =
|
||||
ModuleDescriptor.module("m3")
|
||||
ModuleDescriptor descriptor_m3x =
|
||||
ModuleDescriptor.newModule("m3x")
|
||||
.requires("java.base")
|
||||
.requires("m2")
|
||||
.contains("p3")
|
||||
.requires("m2x")
|
||||
.packages(Set.of("p3"))
|
||||
.build();
|
||||
|
||||
// Set up a ModuleFinder containing all modules for this layer.
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1, descriptor_m2, descriptor_m3);
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1x, descriptor_m2x, descriptor_m3x);
|
||||
|
||||
// Resolves "m1"
|
||||
// Resolves "m1x"
|
||||
Configuration cf = Layer.boot()
|
||||
.configuration()
|
||||
.resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
|
||||
.resolve(finder, ModuleFinder.of(), Set.of("m1x"));
|
||||
|
||||
// map each module to differing class loaders for this test
|
||||
Map<String, ClassLoader> map = new HashMap<>();
|
||||
map.put("m1", MyDiffClassLoader.loader1);
|
||||
map.put("m2", MyDiffClassLoader.loader2);
|
||||
map.put("m3", MyDiffClassLoader.loader2);
|
||||
map.put("m1x", MyDiffClassLoader.loader1);
|
||||
map.put("m2x", MyDiffClassLoader.loader2);
|
||||
map.put("m3x", MyDiffClassLoader.loader2);
|
||||
|
||||
// Create Layer that contains m1 & m2
|
||||
// Create Layer that contains m1x & m2x
|
||||
Layer layer = Layer.boot().defineModules(cf, map::get);
|
||||
|
||||
assertTrue(layer.findLoader("m1") == MyDiffClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m2") == MyDiffClassLoader.loader2);
|
||||
assertTrue(layer.findLoader("m3") == MyDiffClassLoader.loader2);
|
||||
assertTrue(layer.findLoader("m1x") == MyDiffClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m2x") == MyDiffClassLoader.loader2);
|
||||
assertTrue(layer.findLoader("m3x") == MyDiffClassLoader.loader2);
|
||||
assertTrue(layer.findLoader("java.base") == null);
|
||||
|
||||
// now use the same loader to load class p1.c1
|
||||
Class p1_c1_class = MyDiffClassLoader.loader1.loadClass("p1.c1");
|
||||
try {
|
||||
p1_c1_class.newInstance();
|
||||
throw new RuntimeException("Failed to get IAE (p2 in m2 is exported to m3 not to m1)");
|
||||
throw new RuntimeException("Failed to get IAE (p2 in m2x is exported to m3x not to m1x)");
|
||||
} catch (IllegalAccessError e) {
|
||||
System.out.println(e.getMessage());
|
||||
if (!e.getMessage().contains("does not export")) {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -25,8 +25,8 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary class p1.c1 defined in m1 tries to access p2.c2 defined in m2.
|
||||
* Access allowed since m1 can read m2 and package p2 is exported to m1.
|
||||
* @summary class p1.c1 defined in m1x tries to access p2.c2 defined in m2x.
|
||||
* Access allowed since m1x can read m2x and package p2 is exported to m1x.
|
||||
* @modules java.base/jdk.internal.misc
|
||||
* @library /test/lib
|
||||
* @compile myloaders/MyDiffClassLoader.java
|
||||
@ -47,14 +47,14 @@ import java.util.Set;
|
||||
import myloaders.MyDiffClassLoader;
|
||||
|
||||
//
|
||||
// ClassLoader1 --> defines m1 --> packages p1
|
||||
// ClassLoader2 --> defines m2 --> packages p2
|
||||
// ClassLoader1 --> defines m1x --> packages p1
|
||||
// ClassLoader2 --> defines m2x --> packages p2
|
||||
//
|
||||
// m1 can read m2
|
||||
// package p2 in m2 is exported to m1
|
||||
// m1x can read m2x
|
||||
// package p2 in m2x is exported to m1x
|
||||
//
|
||||
// class p1.c1 defined in m1 tries to access p2.c2 defined in m2
|
||||
// Access allowed since m1 can read m2 and package p2 is exported to m1.
|
||||
// class p1.c1 defined in m1x tries to access p2.c2 defined in m2x
|
||||
// Access allowed since m1x can read m2x and package p2 is exported to m1x.
|
||||
//
|
||||
public class DiffCL_ExpQualToM1 {
|
||||
|
||||
@ -63,45 +63,45 @@ public class DiffCL_ExpQualToM1 {
|
||||
// publically defined classes within packages of those modules.
|
||||
public void createLayerOnBoot() throws Throwable {
|
||||
|
||||
// Define module: m1
|
||||
// Can read: java.base, m2
|
||||
// Define module: m1x
|
||||
// Can read: java.base, m2x
|
||||
// Packages: p1
|
||||
// Packages exported: p1 is exported to unqualifiedly
|
||||
ModuleDescriptor descriptor_m1 =
|
||||
ModuleDescriptor.module("m1")
|
||||
ModuleDescriptor descriptor_m1x =
|
||||
ModuleDescriptor.newModule("m1x")
|
||||
.requires("java.base")
|
||||
.requires("m2")
|
||||
.requires("m2x")
|
||||
.exports("p1")
|
||||
.build();
|
||||
|
||||
// Define module: m2
|
||||
// Define module: m2x
|
||||
// Can read: java.base
|
||||
// Packages: p2
|
||||
// Packages exported: package p2 is exported to m1
|
||||
ModuleDescriptor descriptor_m2 =
|
||||
ModuleDescriptor.module("m2")
|
||||
// Packages exported: package p2 is exported to m1x
|
||||
ModuleDescriptor descriptor_m2x =
|
||||
ModuleDescriptor.newModule("m2x")
|
||||
.requires("java.base")
|
||||
.exports("p2", Set.of("m1"))
|
||||
.exports("p2", Set.of("m1x"))
|
||||
.build();
|
||||
|
||||
// Set up a ModuleFinder containing all modules for this layer.
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1, descriptor_m2);
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1x, descriptor_m2x);
|
||||
|
||||
// Resolves "m1"
|
||||
// Resolves "m1x"
|
||||
Configuration cf = Layer.boot()
|
||||
.configuration()
|
||||
.resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
|
||||
.resolve(finder, ModuleFinder.of(), Set.of("m1x"));
|
||||
|
||||
// map each module to differing class loaders for this test
|
||||
Map<String, ClassLoader> map = new HashMap<>();
|
||||
map.put("m1", MyDiffClassLoader.loader1);
|
||||
map.put("m2", MyDiffClassLoader.loader2);
|
||||
map.put("m1x", MyDiffClassLoader.loader1);
|
||||
map.put("m2x", MyDiffClassLoader.loader2);
|
||||
|
||||
// Create Layer that contains m1 & m2
|
||||
// Create Layer that contains m1x & m2x
|
||||
Layer layer = Layer.boot().defineModules(cf, map::get);
|
||||
|
||||
assertTrue(layer.findLoader("m1") == MyDiffClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m2") == MyDiffClassLoader.loader2);
|
||||
assertTrue(layer.findLoader("m1x") == MyDiffClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m2x") == MyDiffClassLoader.loader2);
|
||||
assertTrue(layer.findLoader("java.base") == null);
|
||||
|
||||
// now use the same loader to load class p1.c1
|
||||
@ -109,7 +109,7 @@ public class DiffCL_ExpQualToM1 {
|
||||
try {
|
||||
p1_c1_class.newInstance();
|
||||
} catch (IllegalAccessError e) {
|
||||
throw new RuntimeException("Test Failed, an IAE should not be thrown since p2 is exported qualifiedly to m1");
|
||||
throw new RuntimeException("Test Failed, an IAE should not be thrown since p2 is exported qualifiedly to m1x");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -25,8 +25,8 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Test that if module m1 can read module m2, and package p2 in m2 is
|
||||
* exported unqualifiedly, then class p1.c1 in m1 can read p2.c2 in m2.
|
||||
* @summary Test that if module m1x can read module m2x, and package p2 in m2x is
|
||||
* exported unqualifiedly, then class p1.c1 in m1x can read p2.c2 in m2x.
|
||||
* @modules java.base/jdk.internal.misc
|
||||
* @library /test/lib
|
||||
* @compile myloaders/MyDiffClassLoader.java
|
||||
@ -47,14 +47,14 @@ import java.util.Set;
|
||||
import myloaders.MyDiffClassLoader;
|
||||
|
||||
//
|
||||
// ClassLoader1 --> defines m1 --> packages p1
|
||||
// ClassLoader2 --> defines m2 --> packages p2
|
||||
// ClassLoader1 --> defines m1x --> packages p1
|
||||
// ClassLoader2 --> defines m2x --> packages p2
|
||||
//
|
||||
// m1 can read m2
|
||||
// package p2 in m2 is exported to m1
|
||||
// m1x can read m2x
|
||||
// package p2 in m2x is exported to m1x
|
||||
//
|
||||
// class p1.c1 defined in m1 tries to access p2.c2 defined in m2
|
||||
// Access allowed since m1 can read m2 and package p2 is exported
|
||||
// class p1.c1 defined in m1x tries to access p2.c2 defined in m2x
|
||||
// Access allowed since m1x can read m2x and package p2 is exported
|
||||
// unqualifiedly.
|
||||
//
|
||||
public class DiffCL_ExpUnqual {
|
||||
@ -64,45 +64,45 @@ public class DiffCL_ExpUnqual {
|
||||
// publically defined classes within packages of those modules.
|
||||
public void createLayerOnBoot() throws Throwable {
|
||||
|
||||
// Define module: m1
|
||||
// Can read: java.base, m2
|
||||
// Define module: m1x
|
||||
// Can read: java.base, m2x
|
||||
// Packages: p1
|
||||
// Packages exported: p1 is exported unqualifiedly
|
||||
ModuleDescriptor descriptor_m1 =
|
||||
ModuleDescriptor.module("m1")
|
||||
ModuleDescriptor descriptor_m1x =
|
||||
ModuleDescriptor.newModule("m1x")
|
||||
.requires("java.base")
|
||||
.requires("m2")
|
||||
.requires("m2x")
|
||||
.exports("p1")
|
||||
.build();
|
||||
|
||||
// Define module: m2
|
||||
// Define module: m2x
|
||||
// Can read: java.base
|
||||
// Packages: p2
|
||||
// Packages exported: package p2 is exported to m1
|
||||
ModuleDescriptor descriptor_m2 =
|
||||
ModuleDescriptor.module("m2")
|
||||
// Packages exported: package p2 is exported to m1x
|
||||
ModuleDescriptor descriptor_m2x =
|
||||
ModuleDescriptor.newModule("m2x")
|
||||
.requires("java.base")
|
||||
.exports("p2")
|
||||
.build();
|
||||
|
||||
// Set up a ModuleFinder containing all modules for this layer.
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1, descriptor_m2);
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1x, descriptor_m2x);
|
||||
|
||||
// Resolves "m1"
|
||||
// Resolves "m1x"
|
||||
Configuration cf = Layer.boot()
|
||||
.configuration()
|
||||
.resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
|
||||
.resolve(finder, ModuleFinder.of(), Set.of("m1x"));
|
||||
|
||||
// map each module to differing class loaders for this test
|
||||
Map<String, ClassLoader> map = new HashMap<>();
|
||||
map.put("m1", MyDiffClassLoader.loader1);
|
||||
map.put("m2", MyDiffClassLoader.loader2);
|
||||
map.put("m1x", MyDiffClassLoader.loader1);
|
||||
map.put("m2x", MyDiffClassLoader.loader2);
|
||||
|
||||
// Create Layer that contains m1 & m2
|
||||
// Create Layer that contains m1x & m2x
|
||||
Layer layer = Layer.boot().defineModules(cf, map::get);
|
||||
|
||||
assertTrue(layer.findLoader("m1") == MyDiffClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m2") == MyDiffClassLoader.loader2);
|
||||
assertTrue(layer.findLoader("m1x") == MyDiffClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m2x") == MyDiffClassLoader.loader2);
|
||||
assertTrue(layer.findLoader("java.base") == null);
|
||||
|
||||
// now use the same loader to load class p1.c1
|
||||
@ -110,7 +110,7 @@ public class DiffCL_ExpUnqual {
|
||||
try {
|
||||
p1_c1_class.newInstance();
|
||||
} catch (IllegalAccessError e) {
|
||||
throw new RuntimeException("Test Failed, an IAE should not be thrown since p2 is exported qualifiedly to m1");
|
||||
throw new RuntimeException("Test Failed, an IAE should not be thrown since p2 is exported qualifiedly to m1x");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -25,8 +25,8 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Test that if module m1 can read module m2, but package p2 in m2 is not
|
||||
* exported, then class p1.c1 in m1 can not read p2.c2 in m2.
|
||||
* @summary Test that if module m1x can read module m2x, but package p2 in m2x is not
|
||||
* exported, then class p1.c1 in m1x can not read p2.c2 in m2x.
|
||||
* @modules java.base/jdk.internal.misc
|
||||
* @library /test/lib
|
||||
* @compile myloaders/MyDiffClassLoader.java
|
||||
@ -47,13 +47,13 @@ import java.util.Set;
|
||||
import myloaders.MyDiffClassLoader;
|
||||
|
||||
//
|
||||
// ClassLoader1 --> defines m1 --> packages p1
|
||||
// ClassLoader2 --> defines m2 --> packages p2
|
||||
// ClassLoader1 --> defines m1x --> packages p1
|
||||
// ClassLoader2 --> defines m2x --> packages p2
|
||||
//
|
||||
// m1 can read m2
|
||||
// package p2 in m2 is not exported
|
||||
// m1x can read m2x
|
||||
// package p2 in m2x is not exported
|
||||
//
|
||||
// class p1.c1 defined in m1 tries to access p2.c2 defined in m2
|
||||
// class p1.c1 defined in m1x tries to access p2.c2 defined in m2x
|
||||
// Access denied since p2 is not exported.
|
||||
//
|
||||
public class DiffCL_PkgNotExp {
|
||||
@ -63,52 +63,52 @@ public class DiffCL_PkgNotExp {
|
||||
// publically defined classes within packages of those modules.
|
||||
public void createLayerOnBoot() throws Throwable {
|
||||
|
||||
// Define module: m1
|
||||
// Can read: java.base, m2
|
||||
// Define module: m1x
|
||||
// Can read: java.base, m2x
|
||||
// Packages: p1
|
||||
// Packages exported: p1 is exported unqualifiedly
|
||||
ModuleDescriptor descriptor_m1 =
|
||||
ModuleDescriptor.module("m1")
|
||||
ModuleDescriptor descriptor_m1x =
|
||||
ModuleDescriptor.newModule("m1x")
|
||||
.requires("java.base")
|
||||
.requires("m2")
|
||||
.requires("m2x")
|
||||
.exports("p1")
|
||||
.build();
|
||||
|
||||
// Define module: m2
|
||||
// Define module: m2x
|
||||
// Can read: java.base
|
||||
// Packages: p2
|
||||
// Packages exported: none
|
||||
ModuleDescriptor descriptor_m2 =
|
||||
ModuleDescriptor.module("m2")
|
||||
ModuleDescriptor descriptor_m2x =
|
||||
ModuleDescriptor.newModule("m2x")
|
||||
.requires("java.base")
|
||||
.contains("p2")
|
||||
.packages(Set.of("p2"))
|
||||
.build();
|
||||
|
||||
// Set up a ModuleFinder containing all modules for this layer.
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1, descriptor_m2);
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1x, descriptor_m2x);
|
||||
|
||||
// Resolves "m1"
|
||||
// Resolves "m1x"
|
||||
Configuration cf = Layer.boot()
|
||||
.configuration()
|
||||
.resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
|
||||
.resolve(finder, ModuleFinder.of(), Set.of("m1x"));
|
||||
|
||||
// map each module to differing class loaders for this test
|
||||
Map<String, ClassLoader> map = new HashMap<>();
|
||||
map.put("m1", MyDiffClassLoader.loader1);
|
||||
map.put("m2", MyDiffClassLoader.loader2);
|
||||
map.put("m1x", MyDiffClassLoader.loader1);
|
||||
map.put("m2x", MyDiffClassLoader.loader2);
|
||||
|
||||
// Create Layer that contains m1 & m2
|
||||
// Create Layer that contains m1x & m2x
|
||||
Layer layer = Layer.boot().defineModules(cf, map::get);
|
||||
|
||||
assertTrue(layer.findLoader("m1") == MyDiffClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m2") == MyDiffClassLoader.loader2);
|
||||
assertTrue(layer.findLoader("m1x") == MyDiffClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m2x") == MyDiffClassLoader.loader2);
|
||||
assertTrue(layer.findLoader("java.base") == null);
|
||||
|
||||
// now use the same loader to load class p1.c1
|
||||
Class p1_c1_class = MyDiffClassLoader.loader1.loadClass("p1.c1");
|
||||
try {
|
||||
p1_c1_class.newInstance();
|
||||
throw new RuntimeException("Failed to get IAE (p2 in m2 is not exported)");
|
||||
throw new RuntimeException("Failed to get IAE (p2 in m2x is not exported)");
|
||||
} catch (IllegalAccessError e) {
|
||||
System.out.println(e.getMessage());
|
||||
if (!e.getMessage().contains("does not export")) {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -25,7 +25,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary class p1.c1 defined in m1 tries to access p2.c2 defined in unnamed module.
|
||||
* @summary class p1.c1 defined in m1x tries to access p2.c2 defined in unnamed module.
|
||||
* @library /test/lib
|
||||
* @modules java.base/jdk.internal.misc
|
||||
* @modules java.base/jdk.internal.module
|
||||
@ -50,10 +50,10 @@ import java.util.Set;
|
||||
import myloaders.MyDiffClassLoader;
|
||||
|
||||
//
|
||||
// ClassLoader1 --> defines m1 --> packages p1
|
||||
// package p1 in m1 is exported unqualifiedly
|
||||
// ClassLoader1 --> defines m1x --> packages p1
|
||||
// package p1 in m1x is exported unqualifiedly
|
||||
//
|
||||
// class p1.c1 defined in m1 tries to access p2.c2 defined in
|
||||
// class p1.c1 defined in m1x tries to access p2.c2 defined in
|
||||
// in unnamed module.
|
||||
//
|
||||
// Three access attempts occur in this test:
|
||||
@ -62,7 +62,7 @@ import myloaders.MyDiffClassLoader;
|
||||
// 2. In this scenario a strict module establishes readability
|
||||
// to the particular unnamed module it is trying to access.
|
||||
// Access is allowed.
|
||||
// 3. Module m1 in the test_looseModuleLayer() method
|
||||
// 3. Module m1x in the test_looseModuleLayer() method
|
||||
// is transitioned to a loose module, access
|
||||
// to all unnamed modules is allowed.
|
||||
//
|
||||
@ -71,41 +71,41 @@ public class DiffCL_Umod {
|
||||
// Create Layers over the boot layer to test different
|
||||
// accessing scenarios of a named module to an unnamed module.
|
||||
|
||||
// Module m1 is a strict module and has not established
|
||||
// Module m1x is a strict module and has not established
|
||||
// readability to an unnamed module that p2.c2 is defined in.
|
||||
public void test_strictModuleLayer() throws Throwable {
|
||||
|
||||
// Define module: m1
|
||||
// Define module: m1x
|
||||
// Can read: java.base
|
||||
// Packages: p1
|
||||
// Packages exported: p1 is exported unqualifiedly
|
||||
ModuleDescriptor descriptor_m1 =
|
||||
ModuleDescriptor.module("m1")
|
||||
ModuleDescriptor descriptor_m1x =
|
||||
ModuleDescriptor.newModule("m1x")
|
||||
.requires("java.base")
|
||||
.exports("p1")
|
||||
.build();
|
||||
|
||||
// Set up a ModuleFinder containing all modules for this layer.
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1);
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1x);
|
||||
|
||||
// Resolves "m1"
|
||||
// Resolves "m1x"
|
||||
Configuration cf = Layer.boot()
|
||||
.configuration()
|
||||
.resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
|
||||
.resolve(finder, ModuleFinder.of(), Set.of("m1x"));
|
||||
|
||||
MyDiffClassLoader.loader1 = new MyDiffClassLoader();
|
||||
MyDiffClassLoader.loader2 = new MyDiffClassLoader();
|
||||
|
||||
// map module m1 to class loader.
|
||||
// map module m1x to class loader.
|
||||
// class c2 will be loaded in an unnamed module/loader2
|
||||
// to achieve differing class loaders.
|
||||
Map<String, ClassLoader> map = new HashMap<>();
|
||||
map.put("m1", MyDiffClassLoader.loader1);
|
||||
map.put("m1x", MyDiffClassLoader.loader1);
|
||||
|
||||
// Create Layer that contains m1
|
||||
// Create Layer that contains m1x
|
||||
Layer layer = Layer.boot().defineModules(cf, map::get);
|
||||
|
||||
assertTrue(layer.findLoader("m1") == MyDiffClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m1x") == MyDiffClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("java.base") == null);
|
||||
|
||||
// now use the same loader to load class p1.c1
|
||||
@ -114,109 +114,109 @@ public class DiffCL_Umod {
|
||||
// Attempt access
|
||||
try {
|
||||
p1_c1_class.newInstance();
|
||||
throw new RuntimeException("Test Failed, strict module m1 should not be able " +
|
||||
throw new RuntimeException("Test Failed, strict module m1x should not be able " +
|
||||
"to access public type p2.c2 defined in unnamed module");
|
||||
} catch (IllegalAccessError e) {
|
||||
}
|
||||
}
|
||||
|
||||
// Module m1 is a strict module and has established
|
||||
// Module m1x is a strict module and has established
|
||||
// readability to an unnamed module that p2.c2 is defined in.
|
||||
public void test_strictModuleUnnamedReadableLayer() throws Throwable {
|
||||
|
||||
// Define module: m1
|
||||
// Define module: m1x
|
||||
// Can read: java.base
|
||||
// Packages: p1
|
||||
// Packages exported: p1 is exported unqualifiedly
|
||||
ModuleDescriptor descriptor_m1 =
|
||||
ModuleDescriptor.module("m1")
|
||||
ModuleDescriptor descriptor_m1x =
|
||||
ModuleDescriptor.newModule("m1x")
|
||||
.requires("java.base")
|
||||
.exports("p1")
|
||||
.build();
|
||||
|
||||
// Set up a ModuleFinder containing all modules for this layer.
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1);
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1x);
|
||||
|
||||
// Resolves "m1"
|
||||
// Resolves "m1x"
|
||||
Configuration cf = Layer.boot()
|
||||
.configuration()
|
||||
.resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
|
||||
.resolve(finder, ModuleFinder.of(), Set.of("m1x"));
|
||||
|
||||
MyDiffClassLoader.loader1 = new MyDiffClassLoader();
|
||||
MyDiffClassLoader.loader2 = new MyDiffClassLoader();
|
||||
|
||||
// map module m1 to class loader.
|
||||
// map module m1x to class loader.
|
||||
// class c2 will be loaded in an unnamed module/loader2
|
||||
// to achieve differing class loaders.
|
||||
Map<String, ClassLoader> map = new HashMap<>();
|
||||
map.put("m1", MyDiffClassLoader.loader1);
|
||||
map.put("m1x", MyDiffClassLoader.loader1);
|
||||
|
||||
// Create Layer that contains m1
|
||||
// Create Layer that contains m1x
|
||||
Layer layer = Layer.boot().defineModules(cf, map::get);
|
||||
|
||||
assertTrue(layer.findLoader("m1") == MyDiffClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m1x") == MyDiffClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("java.base") == null);
|
||||
|
||||
// now use the same loader to load class p1.c1ReadEdgeDiffLoader
|
||||
Class p1_c1_class = MyDiffClassLoader.loader1.loadClass("p1.c1ReadEdgeDiffLoader");
|
||||
|
||||
try {
|
||||
// Read edge between m1 and the unnamed module that loads p2.c2 is established in
|
||||
// Read edge between m1x and the unnamed module that loads p2.c2 is established in
|
||||
// c1ReadEdgeDiffLoader's ctor before attempting access.
|
||||
p1_c1_class.newInstance();
|
||||
} catch (IllegalAccessError e) {
|
||||
throw new RuntimeException("Test Failed, module m1 has established readability to p2/c2 loader's " +
|
||||
throw new RuntimeException("Test Failed, module m1x has established readability to p2/c2 loader's " +
|
||||
"unnamed module, access should be allowed: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// Module m1 is a loose module and thus can read all unnamed modules.
|
||||
// Module m1x is a loose module and thus can read all unnamed modules.
|
||||
public void test_looseModuleLayer() throws Throwable {
|
||||
|
||||
// Define module: m1
|
||||
// Define module: m1x
|
||||
// Can read: java.base
|
||||
// Packages: p1
|
||||
// Packages exported: p1 is exported unqualifiedly
|
||||
ModuleDescriptor descriptor_m1 =
|
||||
ModuleDescriptor.module("m1")
|
||||
ModuleDescriptor descriptor_m1x =
|
||||
ModuleDescriptor.newModule("m1x")
|
||||
.requires("java.base")
|
||||
.exports("p1")
|
||||
.build();
|
||||
|
||||
// Set up a ModuleFinder containing all modules for this layer.
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1);
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1x);
|
||||
|
||||
// Resolves "m1"
|
||||
// Resolves "m1x"
|
||||
Configuration cf = Layer.boot()
|
||||
.configuration()
|
||||
.resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
|
||||
.resolve(finder, ModuleFinder.of(), Set.of("m1x"));
|
||||
|
||||
MyDiffClassLoader.loader1 = new MyDiffClassLoader();
|
||||
MyDiffClassLoader.loader2 = new MyDiffClassLoader();
|
||||
|
||||
// map module m1 to class loader.
|
||||
// map module m1x to class loader.
|
||||
// class c2 will be loaded in an unnamed module/loader2
|
||||
// to achieve differing class loaders.
|
||||
Map<String, ClassLoader> map = new HashMap<>();
|
||||
map.put("m1", MyDiffClassLoader.loader1);
|
||||
map.put("m1x", MyDiffClassLoader.loader1);
|
||||
|
||||
// Create Layer that contains m1
|
||||
// Create Layer that contains m1x
|
||||
Layer layer = Layer.boot().defineModules(cf, map::get);
|
||||
|
||||
assertTrue(layer.findLoader("m1") == MyDiffClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m1x") == MyDiffClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("java.base") == null);
|
||||
|
||||
// now use the same loader to load class p1.c1Loose
|
||||
Class p1_c1_class = MyDiffClassLoader.loader1.loadClass("p1.c1Loose");
|
||||
|
||||
// change m1 to read all unnamed modules
|
||||
Module m1 = layer.findModule("m1").get();
|
||||
jdk.internal.module.Modules.addReadsAllUnnamed(m1);
|
||||
// change m1x to read all unnamed modules
|
||||
Module m1x = layer.findModule("m1x").get();
|
||||
jdk.internal.module.Modules.addReadsAllUnnamed(m1x);
|
||||
|
||||
try {
|
||||
p1_c1_class.newInstance();
|
||||
} catch (IllegalAccessError e) {
|
||||
throw new RuntimeException("Test Failed, loose module m1 should be able to access " +
|
||||
throw new RuntimeException("Test Failed, loose module m1x should be able to access " +
|
||||
"public type p2.c2 defined in unnamed module: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -25,7 +25,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary class p3.c3 defined in module m1 tries to access c4 defined in an unnamed package
|
||||
* @summary class p3.c3 defined in module m1x tries to access c4 defined in an unnamed package
|
||||
* and an unnamed module.
|
||||
* @modules java.base/jdk.internal.misc
|
||||
* @library /test/lib
|
||||
@ -48,10 +48,10 @@ import java.util.Set;
|
||||
import myloaders.MyDiffClassLoader;
|
||||
|
||||
//
|
||||
// ClassLoader1 --> defines m1 --> packages p3
|
||||
// package p3 in m1 is exported unqualifiedly
|
||||
// ClassLoader1 --> defines m1x --> packages p3
|
||||
// package p3 in m1x is exported unqualifiedly
|
||||
//
|
||||
// class p3.c3 defined in m1 tries to access c4 defined in
|
||||
// class p3.c3 defined in m1x tries to access c4 defined in
|
||||
// in unnamed module.
|
||||
//
|
||||
// Two access attempts occur in this test:
|
||||
@ -66,41 +66,41 @@ public class DiffCL_UmodUpkg {
|
||||
// Create Layers over the boot layer to test different
|
||||
// accessing scenarios of a named module to an unnamed module.
|
||||
|
||||
// Module m1 is a strict module and has not established
|
||||
// Module m1x is a strict module and has not established
|
||||
// readability to an unnamed module that c4 is defined in.
|
||||
public void test_strictModuleLayer() throws Throwable {
|
||||
|
||||
// Define module: m1
|
||||
// Define module: m1x
|
||||
// Can read: java.base
|
||||
// Packages: p3
|
||||
// Packages exported: p3 is exported unqualifiedly
|
||||
ModuleDescriptor descriptor_m1 =
|
||||
ModuleDescriptor.module("m1")
|
||||
ModuleDescriptor descriptor_m1x =
|
||||
ModuleDescriptor.newModule("m1x")
|
||||
.requires("java.base")
|
||||
.exports("p3")
|
||||
.build();
|
||||
|
||||
// Set up a ModuleFinder containing all modules for this layer.
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1);
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1x);
|
||||
|
||||
// Resolves "m1"
|
||||
// Resolves "m1x"
|
||||
Configuration cf = Layer.boot()
|
||||
.configuration()
|
||||
.resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
|
||||
.resolve(finder, ModuleFinder.of(), Set.of("m1x"));
|
||||
|
||||
MyDiffClassLoader.loader1 = new MyDiffClassLoader();
|
||||
MyDiffClassLoader.loader2 = new MyDiffClassLoader();
|
||||
|
||||
// map module m1 to class loader.
|
||||
// map module m1x to class loader.
|
||||
// class c2 will be loaded in an unnamed module/loader2
|
||||
// to achieve differing class loaders.
|
||||
Map<String, ClassLoader> map = new HashMap<>();
|
||||
map.put("m1", MyDiffClassLoader.loader1);
|
||||
map.put("m1x", MyDiffClassLoader.loader1);
|
||||
|
||||
// Create Layer that contains m1
|
||||
// Create Layer that contains m1x
|
||||
Layer layer = Layer.boot().defineModules(cf, map::get);
|
||||
|
||||
assertTrue(layer.findLoader("m1") == MyDiffClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m1x") == MyDiffClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("java.base") == null);
|
||||
|
||||
// now use the same loader to load class p3.c3
|
||||
@ -109,58 +109,58 @@ public class DiffCL_UmodUpkg {
|
||||
// Attempt access
|
||||
try {
|
||||
p3_c3_class.newInstance();
|
||||
throw new RuntimeException("Test Failed, strict module m1 should not be able to access " +
|
||||
throw new RuntimeException("Test Failed, strict module m1x should not be able to access " +
|
||||
"public type c4 defined in unnamed module");
|
||||
} catch (IllegalAccessError e) {
|
||||
}
|
||||
}
|
||||
|
||||
// Module m1 is a strict module and has established
|
||||
// Module m1x is a strict module and has established
|
||||
// readability to an unnamed module that c4 is defined in.
|
||||
public void test_strictModuleUnnamedReadableLayer() throws Throwable {
|
||||
|
||||
// Define module: m1
|
||||
// Define module: m1x
|
||||
// Can read: java.base
|
||||
// Packages: p3
|
||||
// Packages exported: p3 is exported unqualifiedly
|
||||
ModuleDescriptor descriptor_m1 =
|
||||
ModuleDescriptor.module("m1")
|
||||
ModuleDescriptor descriptor_m1x =
|
||||
ModuleDescriptor.newModule("m1x")
|
||||
.requires("java.base")
|
||||
.exports("p3")
|
||||
.build();
|
||||
|
||||
// Set up a ModuleFinder containing all modules for this layer.
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1);
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1x);
|
||||
|
||||
// Resolves "m1"
|
||||
// Resolves "m1x"
|
||||
Configuration cf = Layer.boot()
|
||||
.configuration()
|
||||
.resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
|
||||
.resolve(finder, ModuleFinder.of(), Set.of("m1x"));
|
||||
|
||||
MyDiffClassLoader.loader1 = new MyDiffClassLoader();
|
||||
MyDiffClassLoader.loader2 = new MyDiffClassLoader();
|
||||
|
||||
// map module m1 to class loader.
|
||||
// map module m1x to class loader.
|
||||
// class c2 will be loaded in an unnamed module/loader2
|
||||
// to achieve differing class loaders.
|
||||
Map<String, ClassLoader> map = new HashMap<>();
|
||||
map.put("m1", MyDiffClassLoader.loader1);
|
||||
map.put("m1x", MyDiffClassLoader.loader1);
|
||||
|
||||
// Create Layer that contains m1
|
||||
// Create Layer that contains m1x
|
||||
Layer layer = Layer.boot().defineModules(cf, map::get);
|
||||
|
||||
assertTrue(layer.findLoader("m1") == MyDiffClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m1x") == MyDiffClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("java.base") == null);
|
||||
|
||||
// now use the same loader to load class p3.c3ReadEdgeDiffLoader
|
||||
Class p3_c3_class = MyDiffClassLoader.loader1.loadClass("p3.c3ReadEdgeDiffLoader");
|
||||
|
||||
try {
|
||||
// Read edge between m1 and the unnamed module that loads c4 is established in
|
||||
// Read edge between m1x and the unnamed module that loads c4 is established in
|
||||
// C3ReadEdgeDiffLoader's ctor before attempting access.
|
||||
p3_c3_class.newInstance();
|
||||
} catch (IllegalAccessError e) {
|
||||
throw new RuntimeException("Test Failed, module m1 has established readability to " +
|
||||
throw new RuntimeException("Test Failed, module m1x has established readability to " +
|
||||
"c4 loader's unnamed module, access should be allowed: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -25,9 +25,9 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Test that if module m1 can read module m2, but package p2 in m2
|
||||
* is exported specifically to module m3, then class p1.c1 in m1 can not
|
||||
* access p2.c2 in m2.
|
||||
* @summary Test that if module m1x can read module m2x, but package p2 in m2x
|
||||
* is exported specifically to module m3x, then class p1.c1 in m1x can not
|
||||
* access p2.c2 in m2x.
|
||||
* @modules java.base/jdk.internal.misc
|
||||
* @library /test/lib
|
||||
* @compile myloaders/MySameClassLoader.java
|
||||
@ -48,15 +48,15 @@ import java.util.Set;
|
||||
import myloaders.MySameClassLoader;
|
||||
|
||||
//
|
||||
// ClassLoader1 --> defines m1 --> packages p1
|
||||
// defines m2 --> packages p2
|
||||
// defines m3 --> packages p3
|
||||
// ClassLoader1 --> defines m1x --> packages p1
|
||||
// defines m2x --> packages p2
|
||||
// defines m3x --> packages p3
|
||||
//
|
||||
// m1 can read m2
|
||||
// package p2 in m2 is exported to m3
|
||||
// m1x can read m2x
|
||||
// package p2 in m2x is exported to m3x
|
||||
//
|
||||
// class p1.c1 defined in m1 tries to access p2.c2 defined in m2
|
||||
// Access denied since although m1 can read m2, p2 is exported only to m3.
|
||||
// class p1.c1 defined in m1x tries to access p2.c2 defined in m2x
|
||||
// Access denied since although m1x can read m2x, p2 is exported only to m3x.
|
||||
//
|
||||
public class ExpQualOther {
|
||||
|
||||
@ -65,66 +65,66 @@ public class ExpQualOther {
|
||||
// publically defined classes within packages of those modules.
|
||||
public void createLayerOnBoot() throws Throwable {
|
||||
|
||||
// Define module: m1
|
||||
// Can read: java.base, m2, m3
|
||||
// Define module: m1x
|
||||
// Can read: java.base, m2x, m3x
|
||||
// Packages: p1
|
||||
// Packages exported: p1 is exported unqualifiedly
|
||||
ModuleDescriptor descriptor_m1 =
|
||||
ModuleDescriptor.module("m1")
|
||||
ModuleDescriptor descriptor_m1x =
|
||||
ModuleDescriptor.newModule("m1x")
|
||||
.requires("java.base")
|
||||
.requires("m2")
|
||||
.requires("m3")
|
||||
.requires("m2x")
|
||||
.requires("m3x")
|
||||
.exports("p1")
|
||||
.build();
|
||||
|
||||
// Define module: m2
|
||||
// Define module: m2x
|
||||
// Can read: java.base
|
||||
// Packages: p2
|
||||
// Packages exported: p2 is exported to m3
|
||||
ModuleDescriptor descriptor_m2 =
|
||||
ModuleDescriptor.module("m2")
|
||||
// Packages exported: p2 is exported to m3x
|
||||
ModuleDescriptor descriptor_m2x =
|
||||
ModuleDescriptor.newModule("m2x")
|
||||
.requires("java.base")
|
||||
.exports("p2", Set.of("m3"))
|
||||
.exports("p2", Set.of("m3x"))
|
||||
.build();
|
||||
|
||||
// Define module: m3
|
||||
// Can read: java.base, m2
|
||||
// Define module: m3x
|
||||
// Can read: java.base, m2x
|
||||
// Packages: p3
|
||||
// Packages exported: none
|
||||
ModuleDescriptor descriptor_m3 =
|
||||
ModuleDescriptor.module("m3")
|
||||
ModuleDescriptor descriptor_m3x =
|
||||
ModuleDescriptor.newModule("m3x")
|
||||
.requires("java.base")
|
||||
.requires("m2")
|
||||
.contains("p3")
|
||||
.requires("m2x")
|
||||
.packages(Set.of("p3"))
|
||||
.build();
|
||||
|
||||
// Set up a ModuleFinder containing all modules for this layer.
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1, descriptor_m2, descriptor_m3);
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1x, descriptor_m2x, descriptor_m3x);
|
||||
|
||||
// Resolves "m1"
|
||||
// Resolves "m1x"
|
||||
Configuration cf = Layer.boot()
|
||||
.configuration()
|
||||
.resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
|
||||
.resolve(finder, ModuleFinder.of(), Set.of("m1x"));
|
||||
|
||||
// map each module to differing class loaders for this test
|
||||
Map<String, ClassLoader> map = new HashMap<>();
|
||||
map.put("m1", MySameClassLoader.loader1);
|
||||
map.put("m2", MySameClassLoader.loader1);
|
||||
map.put("m3", MySameClassLoader.loader1);
|
||||
map.put("m1x", MySameClassLoader.loader1);
|
||||
map.put("m2x", MySameClassLoader.loader1);
|
||||
map.put("m3x", MySameClassLoader.loader1);
|
||||
|
||||
// Create Layer that contains m1 & m2
|
||||
// Create Layer that contains m1x & m2x
|
||||
Layer layer = Layer.boot().defineModules(cf, map::get);
|
||||
|
||||
assertTrue(layer.findLoader("m1") == MySameClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m2") == MySameClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m3") == MySameClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m1x") == MySameClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m2x") == MySameClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m3x") == MySameClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("java.base") == null);
|
||||
|
||||
// now use the same loader to load class p1.c1
|
||||
Class p1_c1_class = MySameClassLoader.loader1.loadClass("p1.c1");
|
||||
try {
|
||||
p1_c1_class.newInstance();
|
||||
throw new RuntimeException("Failed to get IAE (p2 in m2 is exported to m3 not to m1)");
|
||||
throw new RuntimeException("Failed to get IAE (p2 in m2x is exported to m3x not to m1x)");
|
||||
} catch (IllegalAccessError e) {
|
||||
System.out.println(e.getMessage());
|
||||
if (!e.getMessage().contains("does not export")) {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -25,8 +25,8 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Test that if module m1 can read module m2, AND package p2 in m2 is
|
||||
* exported qualifiedly to m1, then class p1.c1 in m1 can read p2.c2 in m2.
|
||||
* @summary Test that if module m1x can read module m2x, AND package p2 in m2x is
|
||||
* exported qualifiedly to m1x, then class p1.c1 in m1x can read p2.c2 in m2x.
|
||||
* @modules java.base/jdk.internal.misc
|
||||
* @library /test/lib
|
||||
* @compile myloaders/MySameClassLoader.java
|
||||
@ -53,52 +53,52 @@ public class ExpQualToM1 {
|
||||
// publically defined classes within packages of those modules.
|
||||
public void createLayerOnBoot() throws Throwable {
|
||||
|
||||
// Define module: m1
|
||||
// Can read: java.base, m2
|
||||
// Define module: m1x
|
||||
// Can read: java.base, m2x
|
||||
// Packages: p1
|
||||
// Packages exported: p1 is exported unqualifiedly
|
||||
ModuleDescriptor descriptor_m1 =
|
||||
ModuleDescriptor.module("m1")
|
||||
ModuleDescriptor descriptor_m1x =
|
||||
ModuleDescriptor.newModule("m1x")
|
||||
.requires("java.base")
|
||||
.requires("m2")
|
||||
.requires("m2x")
|
||||
.exports("p1")
|
||||
.build();
|
||||
|
||||
// Define module: m2
|
||||
// Define module: m2x
|
||||
// Can read: java.base
|
||||
// Packages: p2
|
||||
// Packages exported: p2 is exported qualifiedly to m1
|
||||
ModuleDescriptor descriptor_m2 =
|
||||
ModuleDescriptor.module("m2")
|
||||
// Packages exported: p2 is exported qualifiedly to m1x
|
||||
ModuleDescriptor descriptor_m2x =
|
||||
ModuleDescriptor.newModule("m2x")
|
||||
.requires("java.base")
|
||||
.exports("p2", Set.of("m1"))
|
||||
.exports("p2", Set.of("m1x"))
|
||||
.build();
|
||||
|
||||
// Set up a ModuleFinder containing all modules for this layer.
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1, descriptor_m2);
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1x, descriptor_m2x);
|
||||
|
||||
// Resolves "m1"
|
||||
// Resolves "m1x"
|
||||
Configuration cf = Layer.boot()
|
||||
.configuration()
|
||||
.resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
|
||||
.resolve(finder, ModuleFinder.of(), Set.of("m1x"));
|
||||
|
||||
// map each module to the same class loader for this test
|
||||
Map<String, ClassLoader> map = new HashMap<>();
|
||||
map.put("m1", MySameClassLoader.loader1);
|
||||
map.put("m2", MySameClassLoader.loader1);
|
||||
map.put("m1x", MySameClassLoader.loader1);
|
||||
map.put("m2x", MySameClassLoader.loader1);
|
||||
|
||||
// Create Layer that contains m1 & m2
|
||||
// Create Layer that contains m1x & m2x
|
||||
Layer layer = Layer.boot().defineModules(cf, map::get);
|
||||
|
||||
assertTrue(layer.findLoader("m1") == MySameClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m2") == MySameClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m1x") == MySameClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m2x") == MySameClassLoader.loader1);
|
||||
|
||||
// now use the same loader to load class p1.c1
|
||||
Class p1_c1_class = MySameClassLoader.loader1.loadClass("p1.c1");
|
||||
try {
|
||||
p1_c1_class.newInstance();
|
||||
} catch (IllegalAccessError e) {
|
||||
throw new RuntimeException("Test Failed, an IAE should not be thrown since p2 is exported qualifiedly to m1");
|
||||
throw new RuntimeException("Test Failed, an IAE should not be thrown since p2 is exported qualifiedly to m1x");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -25,8 +25,8 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Test that if module m1 can read module m2, AND package p2 in module2 is
|
||||
* exported unqualifiedly, then class p1.c1 in m1 can read p2.c2 in m2.
|
||||
* @summary Test that if module m1x can read module m2x, AND package p2 in module_two is
|
||||
* exported unqualifiedly, then class p1.c1 in m1x can read p2.c2 in m2x.
|
||||
* @modules java.base/jdk.internal.misc
|
||||
* @library /test/lib
|
||||
* @compile myloaders/MySameClassLoader.java
|
||||
@ -53,45 +53,45 @@ public class ExpUnqual {
|
||||
// publically defined classes within packages of those modules.
|
||||
public void createLayerOnBoot() throws Throwable {
|
||||
|
||||
// Define module: m1
|
||||
// Can read: java.base, m2
|
||||
// Define module: m1x
|
||||
// Can read: java.base, m2x
|
||||
// Packages: p1
|
||||
// Packages exported: p1 is exported unqualifiedly
|
||||
ModuleDescriptor descriptor_m1 =
|
||||
ModuleDescriptor.module("m1")
|
||||
ModuleDescriptor descriptor_m1x =
|
||||
ModuleDescriptor.newModule("m1x")
|
||||
.requires("java.base")
|
||||
.requires("m2")
|
||||
.requires("m2x")
|
||||
.exports("p1")
|
||||
.build();
|
||||
|
||||
// Define module: m2
|
||||
// Define module: m2x
|
||||
// Can read: java.base
|
||||
// Packages: p2
|
||||
// Packages exported: p2 is exported unqualifiedly
|
||||
ModuleDescriptor descriptor_m2 =
|
||||
ModuleDescriptor.module("m2")
|
||||
ModuleDescriptor descriptor_m2x =
|
||||
ModuleDescriptor.newModule("m2x")
|
||||
.requires("java.base")
|
||||
.exports("p2")
|
||||
.build();
|
||||
|
||||
// Set up a ModuleFinder containing all modules for this layer.
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1, descriptor_m2);
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1x, descriptor_m2x);
|
||||
|
||||
// Resolves "m1"
|
||||
// Resolves "m1x"
|
||||
Configuration cf = Layer.boot()
|
||||
.configuration()
|
||||
.resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
|
||||
.resolve(finder, ModuleFinder.of(), Set.of("m1x"));
|
||||
|
||||
// map each module to the same class loader for this test
|
||||
Map<String, ClassLoader> map = new HashMap<>();
|
||||
map.put("m1", MySameClassLoader.loader1);
|
||||
map.put("m2", MySameClassLoader.loader1);
|
||||
map.put("m1x", MySameClassLoader.loader1);
|
||||
map.put("m2x", MySameClassLoader.loader1);
|
||||
|
||||
// Create Layer that contains m1 & m2
|
||||
// Create Layer that contains m1x & m2x
|
||||
Layer layer = Layer.boot().defineModules(cf, map::get);
|
||||
|
||||
assertTrue(layer.findLoader("m1") == MySameClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m2") == MySameClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m1x") == MySameClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m2x") == MySameClassLoader.loader1);
|
||||
|
||||
// now use the same loader to load class p1.c1
|
||||
Class p1_c1_class = MySameClassLoader.loader1.loadClass("p1.c1");
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -25,8 +25,8 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Test if package p2 in module m2 is exported to all unnamed,
|
||||
* then class p1.c1 in an unnamed module can read p2.c2 in module m2.
|
||||
* @summary Test if package p2 in module m2x is exported to all unnamed,
|
||||
* then class p1.c1 in an unnamed module can read p2.c2 in module m2x.
|
||||
* @library /test/lib
|
||||
* @modules java.base/jdk.internal.misc
|
||||
* @modules java.base/jdk.internal.module
|
||||
@ -49,15 +49,15 @@ import java.util.Set;
|
||||
import myloaders.MySameClassLoader;
|
||||
|
||||
//
|
||||
// ClassLoader1 --> defines m1 --> no packages
|
||||
// defines m2 --> packages p2
|
||||
// ClassLoader1 --> defines m1x --> no packages
|
||||
// defines m2x --> packages p2
|
||||
//
|
||||
// m1 can read m2
|
||||
// package p2 in m2 is exported unqualifiedly
|
||||
// m1x can read m2x
|
||||
// package p2 in m2x is exported unqualifiedly
|
||||
//
|
||||
// class p1.c1 defined in an unnamed module tries to access p2.c2 defined in m2
|
||||
// class p1.c1 defined in an unnamed module tries to access p2.c2 defined in m2x
|
||||
// Access allowed, an unnamed module can read all modules and p2 in module
|
||||
// m2 is exported to all unnamed modules.
|
||||
// m2x is exported to all unnamed modules.
|
||||
|
||||
public class ExportAllUnnamed {
|
||||
|
||||
@ -66,51 +66,51 @@ public class ExportAllUnnamed {
|
||||
// publically defined classes within packages of those modules.
|
||||
public void createLayerOnBoot() throws Throwable {
|
||||
|
||||
// Define module: m1
|
||||
// Can read: java.base, m2
|
||||
// Define module: m1x
|
||||
// Can read: java.base, m2x
|
||||
// Packages: none
|
||||
// Packages exported: none
|
||||
ModuleDescriptor descriptor_m1 =
|
||||
ModuleDescriptor.module("m1")
|
||||
ModuleDescriptor descriptor_m1x =
|
||||
ModuleDescriptor.newModule("m1x")
|
||||
.requires("java.base")
|
||||
.requires("m2")
|
||||
.requires("m2x")
|
||||
.build();
|
||||
|
||||
// Define module: m2
|
||||
// Define module: m2x
|
||||
// Can read: java.base
|
||||
// Packages: p2
|
||||
// Packages exported: p2 is exported unqualifiedly
|
||||
ModuleDescriptor descriptor_m2 =
|
||||
ModuleDescriptor.module("m2")
|
||||
ModuleDescriptor descriptor_m2x =
|
||||
ModuleDescriptor.newModule("m2x")
|
||||
.requires("java.base")
|
||||
.exports("p2", Set.of("m1"))
|
||||
.exports("p2", Set.of("m1x"))
|
||||
.build();
|
||||
|
||||
// Set up a ModuleFinder containing all modules for this layer.
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1, descriptor_m2);
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1x, descriptor_m2x);
|
||||
|
||||
// Resolves "m1"
|
||||
// Resolves "m1x"
|
||||
Configuration cf = Layer.boot()
|
||||
.configuration()
|
||||
.resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
|
||||
.resolve(finder, ModuleFinder.of(), Set.of("m1x"));
|
||||
|
||||
// map each module to differing class loaders for this test
|
||||
Map<String, ClassLoader> map = new HashMap<>();
|
||||
map.put("m1", MySameClassLoader.loader1);
|
||||
map.put("m2", MySameClassLoader.loader1);
|
||||
map.put("m1x", MySameClassLoader.loader1);
|
||||
map.put("m2x", MySameClassLoader.loader1);
|
||||
|
||||
// Create Layer that contains m1 & m2
|
||||
// Create Layer that contains m1x & m2x
|
||||
Layer layer = Layer.boot().defineModules(cf, map::get);
|
||||
|
||||
assertTrue(layer.findLoader("m1") == MySameClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m2") == MySameClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m1x") == MySameClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m2x") == MySameClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("java.base") == null);
|
||||
|
||||
Class p2_c2_class = MySameClassLoader.loader1.loadClass("p2.c2");
|
||||
Module m2 = p2_c2_class.getModule();
|
||||
Module m2x = p2_c2_class.getModule();
|
||||
|
||||
// Export m2/p2 to all unnamed modules.
|
||||
jdk.internal.module.Modules.addExportsToAllUnnamed(m2, "p2");
|
||||
// Export m2x/p2 to all unnamed modules.
|
||||
jdk.internal.module.Modules.addExportsToAllUnnamed(m2x, "p2");
|
||||
|
||||
// now use the same loader to load class p1.c1
|
||||
Class p1_c1_class = MySameClassLoader.loader1.loadClass("p1.c1");
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -25,8 +25,8 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Test that if module m1 can read module m2, but package p2 in m2 is not
|
||||
* exported, then class p1.c1 in m1 can not read p2.c2 in m2.
|
||||
* @summary Test that if module m1x can read module m2x, but package p2 in m2x is not
|
||||
* exported, then class p1.c1 in m1x can not read p2.c2 in m2x.
|
||||
* @modules java.base/jdk.internal.misc
|
||||
* @library /test/lib
|
||||
* @compile myloaders/MySameClassLoader.java
|
||||
@ -47,13 +47,13 @@ import java.util.Set;
|
||||
import myloaders.MySameClassLoader;
|
||||
|
||||
//
|
||||
// ClassLoader1 --> defines m1 --> packages p1
|
||||
// defines m2 --> packages p2
|
||||
// ClassLoader1 --> defines m1x --> packages p1
|
||||
// defines m2x --> packages p2
|
||||
//
|
||||
// m1 can read m2
|
||||
// package p2 in m2 is not exported
|
||||
// m1x can read m2x
|
||||
// package p2 in m2x is not exported
|
||||
//
|
||||
// class p1.c1 defined in m1 tries to access p2.c2 defined in m2
|
||||
// class p1.c1 defined in m1x tries to access p2.c2 defined in m2x
|
||||
// Access denied since p2 is not exported.
|
||||
//
|
||||
public class PkgNotExp {
|
||||
@ -63,51 +63,51 @@ public class PkgNotExp {
|
||||
// publically defined classes within packages of those modules.
|
||||
public void createLayerOnBoot() throws Throwable {
|
||||
|
||||
// Define module: m1
|
||||
// Can read: java.base, m2
|
||||
// Define module: m1x
|
||||
// Can read: java.base, m2x
|
||||
// Packages: p1
|
||||
// Packages exported: p1 is exported unqualifiedly
|
||||
ModuleDescriptor descriptor_m1 =
|
||||
ModuleDescriptor.module("m1")
|
||||
ModuleDescriptor descriptor_m1x =
|
||||
ModuleDescriptor.newModule("m1x")
|
||||
.requires("java.base")
|
||||
.requires("m2")
|
||||
.requires("m2x")
|
||||
.exports("p1")
|
||||
.build();
|
||||
|
||||
// Define module: m2
|
||||
// Define module: m2x
|
||||
// Can read: java.base
|
||||
// Packages: p2
|
||||
// Packages exported: none
|
||||
ModuleDescriptor descriptor_m2 =
|
||||
ModuleDescriptor.module("m2")
|
||||
ModuleDescriptor descriptor_m2x =
|
||||
ModuleDescriptor.newModule("m2x")
|
||||
.requires("java.base")
|
||||
.contains("p2")
|
||||
.packages(Set.of("p2"))
|
||||
.build();
|
||||
|
||||
// Set up a ModuleFinder containing all modules for this layer.
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1, descriptor_m2);
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1x, descriptor_m2x);
|
||||
|
||||
// Resolves "m1"
|
||||
// Resolves "m1x"
|
||||
Configuration cf = Layer.boot()
|
||||
.configuration()
|
||||
.resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
|
||||
.resolve(finder, ModuleFinder.of(), Set.of("m1x"));
|
||||
|
||||
// map each module to the same class loader for this test
|
||||
Map<String, ClassLoader> map = new HashMap<>();
|
||||
map.put("m1", MySameClassLoader.loader1);
|
||||
map.put("m2", MySameClassLoader.loader1);
|
||||
map.put("m1x", MySameClassLoader.loader1);
|
||||
map.put("m2x", MySameClassLoader.loader1);
|
||||
|
||||
// Create Layer that contains m1 and m2
|
||||
// Create Layer that contains m1x and m2x
|
||||
Layer layer = Layer.boot().defineModules(cf, map::get);
|
||||
|
||||
assertTrue(layer.findLoader("m1") == MySameClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m2") == MySameClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m1x") == MySameClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m2x") == MySameClassLoader.loader1);
|
||||
|
||||
// now use the same loader to load class p1.c1
|
||||
Class p1_c1_class = MySameClassLoader.loader1.loadClass("p1.c1");
|
||||
try {
|
||||
p1_c1_class.newInstance();
|
||||
throw new RuntimeException("Failed to get IAE (p2 in m2 is not exported)");
|
||||
throw new RuntimeException("Failed to get IAE (p2 in m2x is not exported)");
|
||||
} catch (IllegalAccessError e) {
|
||||
System.out.println(e.getMessage());
|
||||
if (!e.getMessage().contains("does not export")) {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -25,7 +25,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary class p1.c1 defined in m1 tries to access p2.c2 defined in unnamed module.
|
||||
* @summary class p1.c1 defined in m1x tries to access p2.c2 defined in unnamed module.
|
||||
* @library /test/lib
|
||||
* @modules java.base/jdk.internal.misc
|
||||
* @modules java.base/jdk.internal.module
|
||||
@ -50,10 +50,10 @@ import java.util.Set;
|
||||
import myloaders.MySameClassLoader;
|
||||
|
||||
//
|
||||
// ClassLoader1 --> defines m1 --> packages p1
|
||||
// package p1 in m1 is exported unqualifiedly
|
||||
// ClassLoader1 --> defines m1x --> packages p1
|
||||
// package p1 in m1x is exported unqualifiedly
|
||||
//
|
||||
// class p1.c1 defined in m1 tries to access p2.c2 defined in
|
||||
// class p1.c1 defined in m1x tries to access p2.c2 defined in
|
||||
// in unnamed module.
|
||||
//
|
||||
// Three access attempts occur in this test:
|
||||
@ -62,7 +62,7 @@ import myloaders.MySameClassLoader;
|
||||
// 2. In this scenario a strict module establishes readability
|
||||
// to the particular unnamed module it is trying to access.
|
||||
// Access is allowed.
|
||||
// 3. Module m1 in the test_looseModuleLayer() method
|
||||
// 3. Module m1x in the test_looseModuleLayer() method
|
||||
// is transitioned to a loose module, access
|
||||
// to all unnamed modules is allowed.
|
||||
//
|
||||
@ -71,38 +71,38 @@ public class Umod {
|
||||
// Create Layers over the boot layer to test different
|
||||
// accessing scenarios of a named module to an unnamed module.
|
||||
|
||||
// Module m1 is a strict module and has not established
|
||||
// Module m1x is a strict module and has not established
|
||||
// readability to an unnamed module that p2.c2 is defined in.
|
||||
public void test_strictModuleLayer() throws Throwable {
|
||||
|
||||
// Define module: m1
|
||||
// Define module: m1x
|
||||
// Can read: java.base
|
||||
// Packages: p1
|
||||
// Packages exported: p1 is exported unqualifiedly
|
||||
ModuleDescriptor descriptor_m1 =
|
||||
ModuleDescriptor.module("m1")
|
||||
ModuleDescriptor descriptor_m1x =
|
||||
ModuleDescriptor.newModule("m1x")
|
||||
.requires("java.base")
|
||||
.exports("p1")
|
||||
.build();
|
||||
|
||||
// Set up a ModuleFinder containing all modules for this layer.
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1);
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1x);
|
||||
|
||||
// Resolves "m1"
|
||||
// Resolves "m1x"
|
||||
Configuration cf = Layer.boot()
|
||||
.configuration()
|
||||
.resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
|
||||
.resolve(finder, ModuleFinder.of(), Set.of("m1x"));
|
||||
|
||||
// map module m1 to class loader.
|
||||
// map module m1x to class loader.
|
||||
// class c2 will be loaded in an unnamed module/loader.
|
||||
MySameClassLoader loader = new MySameClassLoader();
|
||||
Map<String, ClassLoader> map = new HashMap<>();
|
||||
map.put("m1", loader);
|
||||
map.put("m1x", loader);
|
||||
|
||||
// Create Layer that contains m1
|
||||
// Create Layer that contains m1x
|
||||
Layer layer = Layer.boot().defineModules(cf, map::get);
|
||||
|
||||
assertTrue(layer.findLoader("m1") == loader);
|
||||
assertTrue(layer.findLoader("m1x") == loader);
|
||||
assertTrue(layer.findLoader("java.base") == null);
|
||||
|
||||
// now use the same loader to load class p1.c1
|
||||
@ -111,103 +111,103 @@ public class Umod {
|
||||
// Attempt access
|
||||
try {
|
||||
p1_c1_class.newInstance();
|
||||
throw new RuntimeException("Test Failed, strict module m1, type p1.c1, should not be able " +
|
||||
throw new RuntimeException("Test Failed, strict module m1x, type p1.c1, should not be able " +
|
||||
"to access public type p2.c2 defined in unnamed module");
|
||||
} catch (IllegalAccessError e) {
|
||||
}
|
||||
}
|
||||
|
||||
// Module m1 is a strict module and has established
|
||||
// Module m1x is a strict module and has established
|
||||
// readability to an unnamed module that p2.c2 is defined in.
|
||||
public void test_strictModuleUnnamedReadableLayer() throws Throwable {
|
||||
|
||||
// Define module: m1
|
||||
// Define module: m1x
|
||||
// Can read: java.base
|
||||
// Packages: p1
|
||||
// Packages exported: p1 is exported unqualifiedly
|
||||
ModuleDescriptor descriptor_m1 =
|
||||
ModuleDescriptor.module("m1")
|
||||
ModuleDescriptor descriptor_m1x =
|
||||
ModuleDescriptor.newModule("m1x")
|
||||
.requires("java.base")
|
||||
.exports("p1")
|
||||
.build();
|
||||
|
||||
// Set up a ModuleFinder containing all modules for this layer.
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1);
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1x);
|
||||
|
||||
// Resolves "m1"
|
||||
// Resolves "m1x"
|
||||
Configuration cf = Layer.boot()
|
||||
.configuration()
|
||||
.resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
|
||||
.resolve(finder, ModuleFinder.of(), Set.of("m1x"));
|
||||
|
||||
MySameClassLoader loader = new MySameClassLoader();
|
||||
// map module m1 to class loader.
|
||||
// map module m1x to class loader.
|
||||
// class c2 will be loaded in an unnamed module/loader.
|
||||
Map<String, ClassLoader> map = new HashMap<>();
|
||||
map.put("m1", loader);
|
||||
map.put("m1x", loader);
|
||||
|
||||
// Create Layer that contains m1
|
||||
// Create Layer that contains m1x
|
||||
Layer layer = Layer.boot().defineModules(cf, map::get);
|
||||
|
||||
assertTrue(layer.findLoader("m1") == loader);
|
||||
assertTrue(layer.findLoader("m1x") == loader);
|
||||
assertTrue(layer.findLoader("java.base") == null);
|
||||
|
||||
// now use the same loader to load class p1.c1ReadEdge
|
||||
Class p1_c1_class = loader.loadClass("p1.c1ReadEdge");
|
||||
|
||||
try {
|
||||
// Read edge between m1 and the unnamed module that loads p2.c2 is established in
|
||||
// Read edge between m1x and the unnamed module that loads p2.c2 is established in
|
||||
// c1ReadEdge's ctor before attempting access.
|
||||
p1_c1_class.newInstance();
|
||||
} catch (IllegalAccessError e) {
|
||||
throw new RuntimeException("Test Failed, strict module m1, type p1.c1ReadEdge, should be able to acccess public type " +
|
||||
throw new RuntimeException("Test Failed, strict module m1x, type p1.c1ReadEdge, should be able to acccess public type " +
|
||||
"p2.c2 defined in unnamed module: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// Module m1 is a loose module and thus can read all unnamed modules.
|
||||
// Module m1x is a loose module and thus can read all unnamed modules.
|
||||
public void test_looseModuleLayer() throws Throwable {
|
||||
|
||||
// Define module: m1
|
||||
// Define module: m1x
|
||||
// Can read: java.base
|
||||
// Packages: p1
|
||||
// Packages exported: p1 is exported unqualifiedly
|
||||
ModuleDescriptor descriptor_m1 =
|
||||
ModuleDescriptor.module("m1")
|
||||
ModuleDescriptor descriptor_m1x =
|
||||
ModuleDescriptor.newModule("m1x")
|
||||
.requires("java.base")
|
||||
.exports("p1")
|
||||
.build();
|
||||
|
||||
// Set up a ModuleFinder containing all modules for this layer.
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1);
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1x);
|
||||
|
||||
// Resolves "m1"
|
||||
// Resolves "m1x"
|
||||
Configuration cf = Layer.boot()
|
||||
.configuration()
|
||||
.resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
|
||||
.resolve(finder, ModuleFinder.of(), Set.of("m1x"));
|
||||
|
||||
MySameClassLoader loader = new MySameClassLoader();
|
||||
// map module m1 to class loader.
|
||||
// map module m1x to class loader.
|
||||
// class c2 will be loaded in an unnamed module/loader.
|
||||
Map<String, ClassLoader> map = new HashMap<>();
|
||||
map.put("m1", loader);
|
||||
map.put("m1x", loader);
|
||||
|
||||
// Create Layer that contains m1
|
||||
// Create Layer that contains m1x
|
||||
Layer layer = Layer.boot().defineModules(cf, map::get);
|
||||
|
||||
assertTrue(layer.findLoader("m1") == loader);
|
||||
assertTrue(layer.findLoader("m1x") == loader);
|
||||
assertTrue(layer.findLoader("java.base") == null);
|
||||
|
||||
// now use the same loader to load class p1.c1Loose
|
||||
Class p1_c1_class = loader.loadClass("p1.c1Loose");
|
||||
|
||||
// change m1 to read all unnamed modules
|
||||
Module m1 = layer.findModule("m1").get();
|
||||
jdk.internal.module.Modules.addReadsAllUnnamed(m1);
|
||||
// change m1x to read all unnamed modules
|
||||
Module m1x = layer.findModule("m1x").get();
|
||||
jdk.internal.module.Modules.addReadsAllUnnamed(m1x);
|
||||
|
||||
try {
|
||||
p1_c1_class.newInstance();
|
||||
} catch (IllegalAccessError e) {
|
||||
throw new RuntimeException("Test Failed, strict module m1, type p1.c1Loose, should be able to acccess public type " +
|
||||
throw new RuntimeException("Test Failed, strict module m1x, type p1.c1Loose, should be able to acccess public type " +
|
||||
"p2.c2 defined in unnamed module: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -25,9 +25,9 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary class p1.c1 defined in an unnamed module tries to access p2.c2 defined in m2.
|
||||
* @summary class p1.c1 defined in an unnamed module tries to access p2.c2 defined in m2x.
|
||||
* Access is denied, since an unnamed module can read all modules but p2 in module
|
||||
* m2 is exported specifically to module m1, not to all modules.
|
||||
* m2x is exported specifically to module m1x, not to all modules.
|
||||
* @modules java.base/jdk.internal.misc
|
||||
* @library /test/lib
|
||||
* @compile myloaders/MyDiffClassLoader.java
|
||||
@ -48,15 +48,15 @@ import java.util.Set;
|
||||
import myloaders.MyDiffClassLoader;
|
||||
|
||||
//
|
||||
// ClassLoader1 --> defines m1 --> no packages
|
||||
// ClassLoader2 --> defines m2 --> packages p2
|
||||
// ClassLoader1 --> defines m1x --> no packages
|
||||
// ClassLoader2 --> defines m2x --> packages p2
|
||||
//
|
||||
// m1 can read m2
|
||||
// package p2 in m2 is not exported
|
||||
// m1x can read m2x
|
||||
// package p2 in m2x is not exported
|
||||
//
|
||||
// class p1.c1 defined in an unnamed module tries to access p2.c2 defined in m2
|
||||
// class p1.c1 defined in an unnamed module tries to access p2.c2 defined in m2x
|
||||
// Access denied, an unnamed module can read all modules but p2 in module
|
||||
// m2 is exported specifically to module m1 not to all modules.
|
||||
// m2x is exported specifically to module m1x not to all modules.
|
||||
//
|
||||
public class UmodDiffCL_ExpQualOther {
|
||||
|
||||
@ -65,53 +65,53 @@ public class UmodDiffCL_ExpQualOther {
|
||||
// publically defined classes within packages of those modules.
|
||||
public void createLayerOnBoot() throws Throwable {
|
||||
|
||||
// Define module: m1
|
||||
// Define module: m1x
|
||||
// Can read: java.base
|
||||
// Packages: none
|
||||
// Packages exported: none
|
||||
ModuleDescriptor descriptor_m1 =
|
||||
ModuleDescriptor.module("m1")
|
||||
ModuleDescriptor descriptor_m1x =
|
||||
ModuleDescriptor.newModule("m1x")
|
||||
.requires("java.base")
|
||||
.requires("m2")
|
||||
.requires("m2x")
|
||||
.build();
|
||||
|
||||
// Define module: m2
|
||||
// Define module: m2x
|
||||
// Can read: java.base
|
||||
// Packages: p2
|
||||
// Packages exported: none
|
||||
ModuleDescriptor descriptor_m2 =
|
||||
ModuleDescriptor.module("m2")
|
||||
ModuleDescriptor descriptor_m2x =
|
||||
ModuleDescriptor.newModule("m2x")
|
||||
.requires("java.base")
|
||||
.exports("p2", Set.of("m1"))
|
||||
.exports("p2", Set.of("m1x"))
|
||||
.build();
|
||||
|
||||
// Set up a ModuleFinder containing all modules for this layer.
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1, descriptor_m2);
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1x, descriptor_m2x);
|
||||
|
||||
// Resolves "m1"
|
||||
// Resolves "m1x"
|
||||
Configuration cf = Layer.boot()
|
||||
.configuration()
|
||||
.resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
|
||||
.resolve(finder, ModuleFinder.of(), Set.of("m1x"));
|
||||
|
||||
// map each module to differing class loaders for this test
|
||||
Map<String, ClassLoader> map = new HashMap<>();
|
||||
map.put("m1", MyDiffClassLoader.loader1);
|
||||
map.put("m2", MyDiffClassLoader.loader2);
|
||||
map.put("m1x", MyDiffClassLoader.loader1);
|
||||
map.put("m2x", MyDiffClassLoader.loader2);
|
||||
|
||||
// Create Layer that contains m1 & m2
|
||||
// Create Layer that contains m1x & m2x
|
||||
Layer layer = Layer.boot().defineModules(cf, map::get);
|
||||
|
||||
assertTrue(layer.findLoader("m1") == MyDiffClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m2") == MyDiffClassLoader.loader2);
|
||||
assertTrue(layer.findLoader("m1x") == MyDiffClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m2x") == MyDiffClassLoader.loader2);
|
||||
assertTrue(layer.findLoader("java.base") == null);
|
||||
|
||||
// now use the same loader to load class p1.c1
|
||||
// NOTE: module m1 does not define a package named p1.
|
||||
// NOTE: module m1x does not define a package named p1.
|
||||
// p1 will be loaded in an unnamed module.
|
||||
Class p1_c1_class = MyDiffClassLoader.loader1.loadClass("p1.c1");
|
||||
try {
|
||||
p1_c1_class.newInstance();
|
||||
throw new RuntimeException("Failed to get IAE (p2 in m2 is exported to m1, not unqualifiedly");
|
||||
throw new RuntimeException("Failed to get IAE (p2 in m2x is exported to m1x, not unqualifiedly");
|
||||
} catch (IllegalAccessError e) {
|
||||
System.out.println(e.getMessage());
|
||||
if (!e.getMessage().contains("does not export")) {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -25,8 +25,8 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary class p1.c1 defined in an unnamed module tries to access p2.c2 defined in m2.
|
||||
* Access allowed, an unnamed module can read all modules and p2 in module m2
|
||||
* @summary class p1.c1 defined in an unnamed module tries to access p2.c2 defined in m2x.
|
||||
* Access allowed, an unnamed module can read all modules and p2 in module m2x
|
||||
* which is exported unqualifiedly.
|
||||
* @modules java.base/jdk.internal.misc
|
||||
* @library /test/lib
|
||||
@ -48,15 +48,15 @@ import java.util.Set;
|
||||
import myloaders.MyDiffClassLoader;
|
||||
|
||||
//
|
||||
// ClassLoader1 --> defines m1 --> no packages
|
||||
// ClassLoader2 --> defines m2 --> packages p2
|
||||
// ClassLoader1 --> defines m1x --> no packages
|
||||
// ClassLoader2 --> defines m2x --> packages p2
|
||||
//
|
||||
// m1 can read m2
|
||||
// package p2 in m2 is exported unqualifiedly.
|
||||
// m1x can read m2x
|
||||
// package p2 in m2x is exported unqualifiedly.
|
||||
//
|
||||
// class p1.c1 defined in an unnamed module tries to access p2.c2 defined in m2
|
||||
// class p1.c1 defined in an unnamed module tries to access p2.c2 defined in m2x
|
||||
// Access allowed, an unnamed module can read all modules and p2 in module
|
||||
// m2 which is exported unqualifiedly.
|
||||
// m2x which is exported unqualifiedly.
|
||||
//
|
||||
public class UmodDiffCL_ExpUnqual {
|
||||
|
||||
@ -65,53 +65,53 @@ public class UmodDiffCL_ExpUnqual {
|
||||
// publically defined classes within packages of those modules.
|
||||
public void createLayerOnBoot() throws Throwable {
|
||||
|
||||
// Define module: m1
|
||||
// Can read: java.base, m2
|
||||
// Define module: m1x
|
||||
// Can read: java.base, m2x
|
||||
// Packages: none
|
||||
// Packages exported: none
|
||||
ModuleDescriptor descriptor_m1 =
|
||||
ModuleDescriptor.module("m1")
|
||||
ModuleDescriptor descriptor_m1x =
|
||||
ModuleDescriptor.newModule("m1x")
|
||||
.requires("java.base")
|
||||
.requires("m2")
|
||||
.requires("m2x")
|
||||
.build();
|
||||
|
||||
// Define module: m2
|
||||
// Define module: m2x
|
||||
// Can read: java.base
|
||||
// Packages: p2
|
||||
// Packages exported: none
|
||||
ModuleDescriptor descriptor_m2 =
|
||||
ModuleDescriptor.module("m2")
|
||||
ModuleDescriptor descriptor_m2x =
|
||||
ModuleDescriptor.newModule("m2x")
|
||||
.requires("java.base")
|
||||
.exports("p2")
|
||||
.build();
|
||||
|
||||
// Set up a ModuleFinder containing all modules for this layer.
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1, descriptor_m2);
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1x, descriptor_m2x);
|
||||
|
||||
// Resolves "m1"
|
||||
// Resolves "m1x"
|
||||
Configuration cf = Layer.boot()
|
||||
.configuration()
|
||||
.resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
|
||||
.resolve(finder, ModuleFinder.of(), Set.of("m1x"));
|
||||
|
||||
// map each module to differing class loaders for this test
|
||||
Map<String, ClassLoader> map = new HashMap<>();
|
||||
map.put("m1", MyDiffClassLoader.loader1);
|
||||
map.put("m2", MyDiffClassLoader.loader2);
|
||||
map.put("m1x", MyDiffClassLoader.loader1);
|
||||
map.put("m2x", MyDiffClassLoader.loader2);
|
||||
|
||||
// Create Layer that contains m1 & m2
|
||||
// Create Layer that contains m1x & m2x
|
||||
Layer layer = Layer.boot().defineModules(cf, map::get);
|
||||
|
||||
assertTrue(layer.findLoader("m1") == MyDiffClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m2") == MyDiffClassLoader.loader2);
|
||||
assertTrue(layer.findLoader("m1x") == MyDiffClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m2x") == MyDiffClassLoader.loader2);
|
||||
assertTrue(layer.findLoader("java.base") == null);
|
||||
|
||||
// NOTE: module m1 does not define a package named p1.
|
||||
// NOTE: module m1x does not define a package named p1.
|
||||
// p1 will be loaded in an unnamed module.
|
||||
Class p1_c1_class = MyDiffClassLoader.loader1.loadClass("p1.c1");
|
||||
try {
|
||||
p1_c1_class.newInstance();
|
||||
} catch (IllegalAccessError e) {
|
||||
throw new RuntimeException("Test Failed, p1.c1 defined in unnamed module can access p2.c2 in module m2");
|
||||
throw new RuntimeException("Test Failed, p1.c1 defined in unnamed module can access p2.c2 in module m2x");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -25,9 +25,9 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary class p1.c1 defined in unnamed module tries to access p2.c2 defined in m2.
|
||||
* @summary class p1.c1 defined in unnamed module tries to access p2.c2 defined in m2x.
|
||||
* Access is denied since even though unnamed module can read all modules, p2
|
||||
* in module m2 is not exported at all.
|
||||
* in module m2x is not exported at all.
|
||||
* @modules java.base/jdk.internal.misc
|
||||
* @library /test/lib
|
||||
* @compile myloaders/MyDiffClassLoader.java
|
||||
@ -47,15 +47,15 @@ import java.util.Set;
|
||||
import myloaders.MyDiffClassLoader;
|
||||
|
||||
//
|
||||
// ClassLoader1 --> defines m1 --> no packages
|
||||
// ClassLoader2 --> defines m2 --> packages p2
|
||||
// ClassLoader1 --> defines m1x --> no packages
|
||||
// ClassLoader2 --> defines m2x --> packages p2
|
||||
//
|
||||
// m1 can read m2
|
||||
// package p2 in m2 is not exported
|
||||
// m1x can read m2x
|
||||
// package p2 in m2x is not exported
|
||||
//
|
||||
// class p1.c1 defined in unnamed module tries to access p2.c2 defined in m2
|
||||
// class p1.c1 defined in unnamed module tries to access p2.c2 defined in m2x
|
||||
// Access denied since even though unnamed module can read all modules, p2
|
||||
// in module m2 is not exported at all.
|
||||
// in module m2x is not exported at all.
|
||||
//
|
||||
public class UmodDiffCL_PkgNotExp {
|
||||
|
||||
@ -64,53 +64,53 @@ public class UmodDiffCL_PkgNotExp {
|
||||
// publically defined classes within packages of those modules.
|
||||
public void createLayerOnBoot() throws Throwable {
|
||||
|
||||
// Define module: m1
|
||||
// Can read: java.base, m2
|
||||
// Define module: m1x
|
||||
// Can read: java.base, m2x
|
||||
// Packages: none
|
||||
// Packages exported: none
|
||||
ModuleDescriptor descriptor_m1 =
|
||||
ModuleDescriptor.module("m1")
|
||||
ModuleDescriptor descriptor_m1x =
|
||||
ModuleDescriptor.newModule("m1x")
|
||||
.requires("java.base")
|
||||
.requires("m2")
|
||||
.requires("m2x")
|
||||
.build();
|
||||
|
||||
// Define module: m2
|
||||
// Define module: m2x
|
||||
// Can read: java.base
|
||||
// Packages: p2
|
||||
// Packages exported: none
|
||||
ModuleDescriptor descriptor_m2 =
|
||||
ModuleDescriptor.module("m2")
|
||||
ModuleDescriptor descriptor_m2x =
|
||||
ModuleDescriptor.newModule("m2x")
|
||||
.requires("java.base")
|
||||
.contains("p2")
|
||||
.packages(Set.of("p2"))
|
||||
.build();
|
||||
|
||||
// Set up a ModuleFinder containing all modules for this layer.
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1, descriptor_m2);
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1x, descriptor_m2x);
|
||||
|
||||
// Resolves "m1"
|
||||
// Resolves "m1x"
|
||||
Configuration cf = Layer.boot()
|
||||
.configuration()
|
||||
.resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
|
||||
.resolve(finder, ModuleFinder.of(), Set.of("m1x"));
|
||||
|
||||
// map each module to differing class loaders for this test
|
||||
Map<String, ClassLoader> map = new HashMap<>();
|
||||
map.put("m1", MyDiffClassLoader.loader1);
|
||||
map.put("m2", MyDiffClassLoader.loader2);
|
||||
map.put("m1x", MyDiffClassLoader.loader1);
|
||||
map.put("m2x", MyDiffClassLoader.loader2);
|
||||
|
||||
// Create Layer that contains m1 & m2
|
||||
// Create Layer that contains m1x & m2x
|
||||
Layer layer = Layer.boot().defineModules(cf, map::get);
|
||||
|
||||
assertTrue(layer.findLoader("m1") == MyDiffClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m2") == MyDiffClassLoader.loader2);
|
||||
assertTrue(layer.findLoader("m1x") == MyDiffClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m2x") == MyDiffClassLoader.loader2);
|
||||
assertTrue(layer.findLoader("java.base") == null);
|
||||
|
||||
// now use the same loader to load class p1.c1
|
||||
// NOTE: module m1 does not define a package named p1.
|
||||
// NOTE: module m1x does not define a package named p1.
|
||||
// p1 will be loaded in an unnamed module.
|
||||
Class p1_c1_class = MyDiffClassLoader.loader1.loadClass("p1.c1");
|
||||
try {
|
||||
p1_c1_class.newInstance();
|
||||
throw new RuntimeException("Failed to get IAE (p2 in m2 is not exported to an unnamed module)");
|
||||
throw new RuntimeException("Failed to get IAE (p2 in m2x is not exported to an unnamed module)");
|
||||
} catch (IllegalAccessError e) {
|
||||
System.out.println(e.getMessage());
|
||||
if (!e.getMessage().contains("does not export")) {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -25,7 +25,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary class p3.c3 defined in module m1 tries to access c4 defined in unnamed module.
|
||||
* @summary class p3.c3 defined in module m1x tries to access c4 defined in unnamed module.
|
||||
* @modules java.base/jdk.internal.misc
|
||||
* @library /test/lib
|
||||
* @compile myloaders/MySameClassLoader.java
|
||||
@ -48,10 +48,10 @@ import java.util.Set;
|
||||
import myloaders.MySameClassLoader;
|
||||
|
||||
//
|
||||
// ClassLoader1 --> defines m1 --> packages p3
|
||||
// package p3 in m1 is exported unqualifiedly
|
||||
// ClassLoader1 --> defines m1x --> packages p3
|
||||
// package p3 in m1x is exported unqualifiedly
|
||||
//
|
||||
// class p3.c3 defined in m1 tries to access c4 defined in
|
||||
// class p3.c3 defined in m1x tries to access c4 defined in
|
||||
// in unnamed module.
|
||||
//
|
||||
// Two access attempts occur in this test:
|
||||
@ -66,38 +66,38 @@ public class UmodUPkg {
|
||||
// Create Layers over the boot layer to test different
|
||||
// accessing scenarios of a named module to an unnamed module.
|
||||
|
||||
// Module m1 is a strict module and has not established
|
||||
// Module m1x is a strict module and has not established
|
||||
// readability to an unnamed module that c4 is defined in.
|
||||
public void test_strictModuleLayer() throws Throwable {
|
||||
|
||||
// Define module: m1
|
||||
// Define module: m1x
|
||||
// Can read: java.base
|
||||
// Packages: p3
|
||||
// Packages exported: p3 is exported unqualifiedly
|
||||
ModuleDescriptor descriptor_m1 =
|
||||
ModuleDescriptor.module("m1")
|
||||
ModuleDescriptor descriptor_m1x =
|
||||
ModuleDescriptor.newModule("m1x")
|
||||
.requires("java.base")
|
||||
.exports("p3")
|
||||
.build();
|
||||
|
||||
// Set up a ModuleFinder containing all modules for this layer.
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1);
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1x);
|
||||
|
||||
// Resolves "m1"
|
||||
// Resolves "m1x"
|
||||
Configuration cf = Layer.boot()
|
||||
.configuration()
|
||||
.resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
|
||||
.resolve(finder, ModuleFinder.of(), Set.of("m1x"));
|
||||
|
||||
// map module m1 to class loader.
|
||||
// map module m1x to class loader.
|
||||
// class c4 will be loaded in an unnamed module/loader.
|
||||
MySameClassLoader loader = new MySameClassLoader();
|
||||
Map<String, ClassLoader> map = new HashMap<>();
|
||||
map.put("m1", loader);
|
||||
map.put("m1x", loader);
|
||||
|
||||
// Create Layer that contains m1
|
||||
// Create Layer that contains m1x
|
||||
Layer layer = Layer.boot().defineModules(cf, map::get);
|
||||
|
||||
assertTrue(layer.findLoader("m1") == loader);
|
||||
assertTrue(layer.findLoader("m1x") == loader);
|
||||
assertTrue(layer.findLoader("java.base") == null);
|
||||
|
||||
// now use the same loader to load class p3.c3
|
||||
@ -106,55 +106,55 @@ public class UmodUPkg {
|
||||
// Attempt access
|
||||
try {
|
||||
p3_c3_class.newInstance();
|
||||
throw new RuntimeException("Test Failed, strict module m1, type p3.c3, should not be able to access " +
|
||||
throw new RuntimeException("Test Failed, strict module m1x, type p3.c3, should not be able to access " +
|
||||
"public type c4 defined in unnamed module");
|
||||
} catch (IllegalAccessError e) {
|
||||
}
|
||||
}
|
||||
|
||||
// Module m1 is a strict module and has established
|
||||
// Module m1x is a strict module and has established
|
||||
// readability to an unnamed module that c4 is defined in.
|
||||
public void test_strictModuleUnnamedReadableLayer() throws Throwable {
|
||||
|
||||
// Define module: m1
|
||||
// Define module: m1x
|
||||
// Can read: java.base
|
||||
// Packages: p3
|
||||
// Packages exported: p3 is exported unqualifiedly
|
||||
ModuleDescriptor descriptor_m1 =
|
||||
ModuleDescriptor.module("m1")
|
||||
ModuleDescriptor descriptor_m1x =
|
||||
ModuleDescriptor.newModule("m1x")
|
||||
.requires("java.base")
|
||||
.exports("p3")
|
||||
.build();
|
||||
|
||||
// Set up a ModuleFinder containing all modules for this layer.
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1);
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1x);
|
||||
|
||||
// Resolves "m1"
|
||||
// Resolves "m1x"
|
||||
Configuration cf = Layer.boot()
|
||||
.configuration()
|
||||
.resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
|
||||
.resolve(finder, ModuleFinder.of(), Set.of("m1x"));
|
||||
|
||||
MySameClassLoader loader = new MySameClassLoader();
|
||||
// map module m1 to class loader.
|
||||
// map module m1x to class loader.
|
||||
// class c4 will be loaded in an unnamed module/loader.
|
||||
Map<String, ClassLoader> map = new HashMap<>();
|
||||
map.put("m1", loader);
|
||||
map.put("m1x", loader);
|
||||
|
||||
// Create Layer that contains m1
|
||||
// Create Layer that contains m1x
|
||||
Layer layer = Layer.boot().defineModules(cf, map::get);
|
||||
|
||||
assertTrue(layer.findLoader("m1") == loader);
|
||||
assertTrue(layer.findLoader("m1x") == loader);
|
||||
assertTrue(layer.findLoader("java.base") == null);
|
||||
|
||||
// now use the same loader to load class p3.c3ReadEdge
|
||||
Class p3_c3_class = loader.loadClass("p3.c3ReadEdge");
|
||||
|
||||
try {
|
||||
// Read edge between m1 and the unnamed module that loads c4 is established in
|
||||
// Read edge between m1x and the unnamed module that loads c4 is established in
|
||||
// c3ReadEdge's ctor before attempting access.
|
||||
p3_c3_class.newInstance();
|
||||
} catch (IllegalAccessError e) {
|
||||
throw new RuntimeException("Test Failed, module m1, type p3.c3ReadEdge, has established readability to " +
|
||||
throw new RuntimeException("Test Failed, module m1x, type p3.c3ReadEdge, has established readability to " +
|
||||
"c4 loader's unnamed module, access should be allowed: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -25,9 +25,9 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary class c5 defined in an unnamed module tries to access p6.c6 defined in m2.
|
||||
* @summary class c5 defined in an unnamed module tries to access p6.c6 defined in m2x.
|
||||
* Access is denied, since an unnamed module can read all modules but p6 in module
|
||||
* m2 is exported specifically to module m1, not to all modules.
|
||||
* m2x is exported specifically to module m1x, not to all modules.
|
||||
* @modules java.base/jdk.internal.misc
|
||||
* @library /test/lib
|
||||
* @compile myloaders/MyDiffClassLoader.java
|
||||
@ -48,15 +48,15 @@ import java.util.Set;
|
||||
import myloaders.MyDiffClassLoader;
|
||||
|
||||
//
|
||||
// ClassLoader1 --> defines m1 --> no packages
|
||||
// ClassLoader2 --> defines m2 --> packages p6
|
||||
// ClassLoader1 --> defines m1x --> no packages
|
||||
// ClassLoader2 --> defines m2x --> packages p6
|
||||
//
|
||||
// m1 can read m2
|
||||
// package p6 in m2 is not exported
|
||||
// m1x can read m2x
|
||||
// package p6 in m2x is not exported
|
||||
//
|
||||
// class c5 defined in an unnamed module tries to access p6.c6 defined in m2
|
||||
// class c5 defined in an unnamed module tries to access p6.c6 defined in m2x
|
||||
// Access denied, an unnamed module can read all modules but p6 in module
|
||||
// m2 is exported specifically to module m1 not to all modules.
|
||||
// m2x is exported specifically to module m1x not to all modules.
|
||||
//
|
||||
public class UmodUpkgDiffCL_ExpQualOther {
|
||||
|
||||
@ -65,51 +65,51 @@ public class UmodUpkgDiffCL_ExpQualOther {
|
||||
// publically defined classes within packages of those modules.
|
||||
public void createLayerOnBoot() throws Throwable {
|
||||
|
||||
// Define module: m1
|
||||
// Can read: java.base, m2
|
||||
// Define module: m1x
|
||||
// Can read: java.base, m2x
|
||||
// Packages: none
|
||||
// Packages exported: none
|
||||
ModuleDescriptor descriptor_m1 =
|
||||
ModuleDescriptor.module("m1")
|
||||
ModuleDescriptor descriptor_m1x =
|
||||
ModuleDescriptor.newModule("m1x")
|
||||
.requires("java.base")
|
||||
.requires("m2")
|
||||
.requires("m2x")
|
||||
.build();
|
||||
|
||||
// Define module: m2
|
||||
// Define module: m2x
|
||||
// Can read: java.base
|
||||
// Packages: p6
|
||||
// Packages exported: p6 exported to m1
|
||||
ModuleDescriptor descriptor_m2 =
|
||||
ModuleDescriptor.module("m2")
|
||||
// Packages exported: p6 exported to m1x
|
||||
ModuleDescriptor descriptor_m2x =
|
||||
ModuleDescriptor.newModule("m2x")
|
||||
.requires("java.base")
|
||||
.exports("p6", Set.of("m1"))
|
||||
.exports("p6", Set.of("m1x"))
|
||||
.build();
|
||||
|
||||
// Set up a ModuleFinder containing all modules for this layer.
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1, descriptor_m2);
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1x, descriptor_m2x);
|
||||
|
||||
// Resolves "m1"
|
||||
// Resolves "m1x"
|
||||
Configuration cf = Layer.boot()
|
||||
.configuration()
|
||||
.resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
|
||||
.resolve(finder, ModuleFinder.of(), Set.of("m1x"));
|
||||
|
||||
// map each module to differing class loaders for this test
|
||||
Map<String, ClassLoader> map = new HashMap<>();
|
||||
map.put("m1", MyDiffClassLoader.loader1);
|
||||
map.put("m2", MyDiffClassLoader.loader2);
|
||||
map.put("m1x", MyDiffClassLoader.loader1);
|
||||
map.put("m2x", MyDiffClassLoader.loader2);
|
||||
|
||||
// Create Layer that contains m1 & m2
|
||||
// Create Layer that contains m1x & m2x
|
||||
Layer layer = Layer.boot().defineModules(cf, map::get);
|
||||
|
||||
assertTrue(layer.findLoader("m1") == MyDiffClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m2") == MyDiffClassLoader.loader2);
|
||||
assertTrue(layer.findLoader("m1x") == MyDiffClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m2x") == MyDiffClassLoader.loader2);
|
||||
assertTrue(layer.findLoader("java.base") == null);
|
||||
|
||||
// now use the same loader to load class c5
|
||||
Class c5_class = MyDiffClassLoader.loader1.loadClass("c5");
|
||||
try {
|
||||
c5_class.newInstance();
|
||||
throw new RuntimeException("Failed to get IAE (p6 in m2 is exported to m1, not unqualifiedly");
|
||||
throw new RuntimeException("Failed to get IAE (p6 in m2x is exported to m1x, not unqualifiedly");
|
||||
} catch (IllegalAccessError e) {
|
||||
System.out.println(e.getMessage());
|
||||
if (!e.getMessage().contains("does not export")) {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -25,8 +25,8 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary class c5 in an unnamed module can read module m2, but package p6 in module m2 is not exported.
|
||||
* Access denied since even though unnamed module can read all modules, p6 in module m2 is not exported at all.
|
||||
* @summary class c5 in an unnamed module can read module m2x, but package p6 in module m2x is not exported.
|
||||
* Access denied since even though unnamed module can read all modules, p6 in module m2x is not exported at all.
|
||||
* @modules java.base/jdk.internal.misc
|
||||
* @library /test/lib
|
||||
* @compile myloaders/MyDiffClassLoader.java
|
||||
@ -47,15 +47,15 @@ import java.util.Set;
|
||||
import myloaders.MyDiffClassLoader;
|
||||
|
||||
//
|
||||
// ClassLoader1 --> defines m1 --> no packages
|
||||
// ClassLoader2 --> defines m2 --> packages p6
|
||||
// ClassLoader1 --> defines m1x --> no packages
|
||||
// ClassLoader2 --> defines m2x --> packages p6
|
||||
//
|
||||
// m1 can read m2
|
||||
// package p6 in m2 is not exported
|
||||
// m1x can read m2x
|
||||
// package p6 in m2x is not exported
|
||||
//
|
||||
// class c5 defined in unnamed module tries to access p6.c6 defined in m2
|
||||
// class c5 defined in unnamed module tries to access p6.c6 defined in m2x
|
||||
// Access denied since even though unnamed module can read all modules, p6
|
||||
// in module m2 is not exported at all.
|
||||
// in module m2x is not exported at all.
|
||||
//
|
||||
public class UmodUpkgDiffCL_NotExp {
|
||||
|
||||
@ -64,53 +64,53 @@ public class UmodUpkgDiffCL_NotExp {
|
||||
// publically defined classes within packages of those modules.
|
||||
public void createLayerOnBoot() throws Throwable {
|
||||
|
||||
// Define module: m1
|
||||
// Can read: java.base, m2
|
||||
// Define module: m1x
|
||||
// Can read: java.base, m2x
|
||||
// Packages: none
|
||||
// Packages exported: none
|
||||
ModuleDescriptor descriptor_m1 =
|
||||
ModuleDescriptor.module("m1")
|
||||
ModuleDescriptor descriptor_m1x =
|
||||
ModuleDescriptor.newModule("m1x")
|
||||
.requires("java.base")
|
||||
.requires("m2")
|
||||
.requires("m2x")
|
||||
.build();
|
||||
|
||||
// Define module: m2
|
||||
// Define module: m2x
|
||||
// Can read: java.base
|
||||
// Packages: p6
|
||||
// Packages exported: none
|
||||
ModuleDescriptor descriptor_m2 =
|
||||
ModuleDescriptor.module("m2")
|
||||
ModuleDescriptor descriptor_m2x =
|
||||
ModuleDescriptor.newModule("m2x")
|
||||
.requires("java.base")
|
||||
.contains("p6")
|
||||
.packages(Set.of("p6"))
|
||||
.build();
|
||||
|
||||
// Set up a ModuleFinder containing all modules for this layer.
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1, descriptor_m2);
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1x, descriptor_m2x);
|
||||
|
||||
// Resolves "m1"
|
||||
// Resolves "m1x"
|
||||
Configuration cf = Layer.boot()
|
||||
.configuration()
|
||||
.resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
|
||||
.resolve(finder, ModuleFinder.of(), Set.of("m1x"));
|
||||
|
||||
// map each module to differing class loaders for this test
|
||||
Map<String, ClassLoader> map = new HashMap<>();
|
||||
map.put("m1", MyDiffClassLoader.loader1);
|
||||
map.put("m2", MyDiffClassLoader.loader2);
|
||||
map.put("m1x", MyDiffClassLoader.loader1);
|
||||
map.put("m2x", MyDiffClassLoader.loader2);
|
||||
|
||||
// Create Layer that contains m1 & m2
|
||||
// Create Layer that contains m1x & m2x
|
||||
Layer layer = Layer.boot().defineModules(cf, map::get);
|
||||
|
||||
assertTrue(layer.findLoader("m1") == MyDiffClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m2") == MyDiffClassLoader.loader2);
|
||||
assertTrue(layer.findLoader("m1x") == MyDiffClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m2x") == MyDiffClassLoader.loader2);
|
||||
assertTrue(layer.findLoader("java.base") == null);
|
||||
|
||||
// now use the same loader to load class c5
|
||||
// NOTE: module m1 does not define any packages.
|
||||
// NOTE: module m1x does not define any packages.
|
||||
// c5 will be loaded in an unnamed module.
|
||||
Class c5_class = MyDiffClassLoader.loader1.loadClass("c5");
|
||||
try {
|
||||
c5_class.newInstance();
|
||||
throw new RuntimeException("Failed to get IAE (p6 in m2 is not exported to " +
|
||||
throw new RuntimeException("Failed to get IAE (p6 in m2x is not exported to " +
|
||||
"an unnamed module that c5 is defined within)");
|
||||
} catch (IllegalAccessError e) {
|
||||
System.out.println(e.getMessage());
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -25,8 +25,8 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Test that if class c5 in an unnamed module can read package p6 in module m2, but package p6 in module m2 is
|
||||
* exported qualifiedly to module m3, then class c5 in an unnamed module can not read p6.c6 in module m2.
|
||||
* @summary Test that if class c5 in an unnamed module can read package p6 in module m2x, but package p6 in module m2x is
|
||||
* exported qualifiedly to module m3x, then class c5 in an unnamed module can not read p6.c6 in module m2x.
|
||||
* @modules java.base/jdk.internal.misc
|
||||
* @library /test/lib
|
||||
* @compile myloaders/MySameClassLoader.java
|
||||
@ -47,15 +47,15 @@ import java.util.Set;
|
||||
import myloaders.MySameClassLoader;
|
||||
|
||||
//
|
||||
// ClassLoader1 --> defines m1 --> no packages
|
||||
// defines m2 --> packages p6
|
||||
// defines m3 --> packages p3
|
||||
// ClassLoader1 --> defines m1x --> no packages
|
||||
// defines m2x --> packages p6
|
||||
// defines m3x --> packages p3
|
||||
//
|
||||
// m1 can read m2
|
||||
// package p6 in m2 is exported to m3
|
||||
// m1x can read m2x
|
||||
// package p6 in m2x is exported to m3x
|
||||
//
|
||||
// class c5 defined in m1 tries to access p6.c6 defined in m2
|
||||
// Access denied since although m1 can read m2, p6 is exported only to m3.
|
||||
// class c5 defined in m1x tries to access p6.c6 defined in m2x
|
||||
// Access denied since although m1x can read m2x, p6 is exported only to m3x.
|
||||
//
|
||||
public class UmodUpkg_ExpQualOther {
|
||||
|
||||
@ -64,63 +64,63 @@ public class UmodUpkg_ExpQualOther {
|
||||
// publically defined classes within packages of those modules.
|
||||
public void createLayerOnBoot() throws Throwable {
|
||||
|
||||
// Define module: m1 (need to define m1 to establish the Layer successfully)
|
||||
// Can read: java.base, m2, m3
|
||||
// Define module: m1x (need to define m1x to establish the Layer successfully)
|
||||
// Can read: java.base, m2x, m3x
|
||||
// Packages: none
|
||||
// Packages exported: none
|
||||
ModuleDescriptor descriptor_m1 =
|
||||
ModuleDescriptor.module("m1")
|
||||
ModuleDescriptor descriptor_m1x =
|
||||
ModuleDescriptor.newModule("m1x")
|
||||
.requires("java.base")
|
||||
.requires("m2")
|
||||
.requires("m3")
|
||||
.requires("m2x")
|
||||
.requires("m3x")
|
||||
.build();
|
||||
|
||||
// Define module: m2
|
||||
// Define module: m2x
|
||||
// Can read: java.base
|
||||
// Packages: p6
|
||||
// Packages exported: p6 is exported to m3
|
||||
ModuleDescriptor descriptor_m2 =
|
||||
ModuleDescriptor.module("m2")
|
||||
// Packages exported: p6 is exported to m3x
|
||||
ModuleDescriptor descriptor_m2x =
|
||||
ModuleDescriptor.newModule("m2x")
|
||||
.requires("java.base")
|
||||
.exports("p6", Set.of("m3"))
|
||||
.exports("p6", Set.of("m3x"))
|
||||
.build();
|
||||
|
||||
// Define module: m3
|
||||
// Define module: m3x
|
||||
// Can read: java.base
|
||||
// Packages: p3
|
||||
// Packages exported: none
|
||||
ModuleDescriptor descriptor_m3 =
|
||||
ModuleDescriptor.module("m3")
|
||||
ModuleDescriptor descriptor_m3x =
|
||||
ModuleDescriptor.newModule("m3x")
|
||||
.requires("java.base")
|
||||
.build();
|
||||
|
||||
// Set up a ModuleFinder containing all modules for this layer.
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1, descriptor_m2, descriptor_m3);
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1x, descriptor_m2x, descriptor_m3x);
|
||||
|
||||
// Resolves "m1"
|
||||
// Resolves "m1x"
|
||||
Configuration cf = Layer.boot()
|
||||
.configuration()
|
||||
.resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
|
||||
.resolve(finder, ModuleFinder.of(), Set.of("m1x"));
|
||||
|
||||
// map each module to differing class loaders for this test
|
||||
Map<String, ClassLoader> map = new HashMap<>();
|
||||
map.put("m1", MySameClassLoader.loader1);
|
||||
map.put("m2", MySameClassLoader.loader1);
|
||||
map.put("m3", MySameClassLoader.loader1);
|
||||
map.put("m1x", MySameClassLoader.loader1);
|
||||
map.put("m2x", MySameClassLoader.loader1);
|
||||
map.put("m3x", MySameClassLoader.loader1);
|
||||
|
||||
// Create Layer that contains m1, m2 and m3
|
||||
// Create Layer that contains m1x, m2x and m3x
|
||||
Layer layer = Layer.boot().defineModules(cf, map::get);
|
||||
|
||||
assertTrue(layer.findLoader("m1") == MySameClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m2") == MySameClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m3") == MySameClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m1x") == MySameClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m2x") == MySameClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m3x") == MySameClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("java.base") == null);
|
||||
|
||||
// now use the same loader to load class c5
|
||||
Class c5_class = MySameClassLoader.loader1.loadClass("c5");
|
||||
try {
|
||||
c5_class.newInstance();
|
||||
throw new RuntimeException("Failed to get IAE (p6 in m2 is exported to m3, not unqualifiedly to everyone)");
|
||||
throw new RuntimeException("Failed to get IAE (p6 in m2x is exported to m3x, not unqualifiedly to everyone)");
|
||||
} catch (IllegalAccessError e) {
|
||||
System.out.println(e.getMessage());
|
||||
if (!e.getMessage().contains("does not export")) {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -25,8 +25,8 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Test if package p6 in module m2 is not exported, then class c5
|
||||
* in an unnamed module can not access p6.c2 in module m2.
|
||||
* @summary Test if package p6 in module m2x is not exported, then class c5
|
||||
* in an unnamed module can not access p6.c2 in module m2x.
|
||||
* @modules java.base/jdk.internal.misc
|
||||
* @library /test/lib
|
||||
* @compile myloaders/MySameClassLoader.java
|
||||
@ -46,13 +46,13 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import myloaders.MySameClassLoader;
|
||||
|
||||
// ClassLoader1 --> defines m1 --> no packages
|
||||
// defines m2 --> packages p6
|
||||
// ClassLoader1 --> defines m1x --> no packages
|
||||
// defines m2x --> packages p6
|
||||
//
|
||||
// m1 can read m2
|
||||
// package p6 in m2 is not exported
|
||||
// m1x can read m2x
|
||||
// package p6 in m2x is not exported
|
||||
//
|
||||
// class c5 defined in an unnamed module tries to access p6.c2 defined in m2
|
||||
// class c5 defined in an unnamed module tries to access p6.c2 defined in m2x
|
||||
// Access denied since p6 is not exported.
|
||||
//
|
||||
public class UmodUpkg_NotExp {
|
||||
@ -62,51 +62,51 @@ public class UmodUpkg_NotExp {
|
||||
// publically defined classes within packages of those modules.
|
||||
public void createLayerOnBoot() throws Throwable {
|
||||
|
||||
// Define module: m1
|
||||
// Can read: java.base, m2
|
||||
// Define module: m1x
|
||||
// Can read: java.base, m2x
|
||||
// Packages: none
|
||||
// Packages exported: none
|
||||
ModuleDescriptor descriptor_m1 =
|
||||
ModuleDescriptor.module("m1")
|
||||
ModuleDescriptor descriptor_m1x =
|
||||
ModuleDescriptor.newModule("m1x")
|
||||
.requires("java.base")
|
||||
.requires("m2")
|
||||
.requires("m2x")
|
||||
.build();
|
||||
|
||||
// Define module: m2
|
||||
// Define module: m2x
|
||||
// Can read: java.base
|
||||
// Packages: p6
|
||||
// Packages exported: none
|
||||
ModuleDescriptor descriptor_m2 =
|
||||
ModuleDescriptor.module("m2")
|
||||
ModuleDescriptor descriptor_m2x =
|
||||
ModuleDescriptor.newModule("m2x")
|
||||
.requires("java.base")
|
||||
.contains("p6")
|
||||
.packages(Set.of("p6"))
|
||||
.build();
|
||||
|
||||
// Set up a ModuleFinder containing all modules for this layer.
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1, descriptor_m2);
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1x, descriptor_m2x);
|
||||
|
||||
// Resolves "m1"
|
||||
// Resolves "m1x"
|
||||
Configuration cf = Layer.boot()
|
||||
.configuration()
|
||||
.resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
|
||||
.resolve(finder, ModuleFinder.of(), Set.of("m1x"));
|
||||
|
||||
// map each module to the same class loader for this test
|
||||
Map<String, ClassLoader> map = new HashMap<>();
|
||||
map.put("m1", MySameClassLoader.loader1);
|
||||
map.put("m2", MySameClassLoader.loader1);
|
||||
map.put("m1x", MySameClassLoader.loader1);
|
||||
map.put("m2x", MySameClassLoader.loader1);
|
||||
|
||||
// Create Layer that contains m1 and m2
|
||||
// Create Layer that contains m1x and m2x
|
||||
Layer layer = Layer.boot().defineModules(cf, map::get);
|
||||
|
||||
assertTrue(layer.findLoader("m1") == MySameClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m2") == MySameClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m1x") == MySameClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m2x") == MySameClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("java.base") == null);
|
||||
|
||||
// now use the same loader to load class c5
|
||||
Class c5_class = MySameClassLoader.loader1.loadClass("c5");
|
||||
try {
|
||||
c5_class.newInstance();
|
||||
throw new RuntimeException("Failed to get IAE (p6 in m2 is not exported)");
|
||||
throw new RuntimeException("Failed to get IAE (p6 in m2x is not exported)");
|
||||
} catch (IllegalAccessError e) {
|
||||
System.out.println(e.getMessage());
|
||||
if (!e.getMessage().contains("does not export")) {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -25,8 +25,8 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Test that if package p2 in module m2 is exported to module m3,
|
||||
* then class p1.c1 in an unnamed module can not read p2.c2 in module m2.
|
||||
* @summary Test that if package p2 in module m2x is exported to module m3x,
|
||||
* then class p1.c1 in an unnamed module can not read p2.c2 in module m2x.
|
||||
* @modules java.base/jdk.internal.misc
|
||||
* @library /test/lib
|
||||
* @compile myloaders/MySameClassLoader.java
|
||||
@ -47,15 +47,15 @@ import java.util.Set;
|
||||
import myloaders.MySameClassLoader;
|
||||
|
||||
//
|
||||
// ClassLoader1 --> defines m1 --> no packages
|
||||
// defines m2 --> packages p2
|
||||
// defines m3 --> packages p3
|
||||
// ClassLoader1 --> defines m1x --> no packages
|
||||
// defines m2x --> packages p2
|
||||
// defines m3x --> packages p3
|
||||
//
|
||||
// m1 can read m2
|
||||
// package p2 in m2 is exported to m3
|
||||
// m1x can read m2x
|
||||
// package p2 in m2x is exported to m3x
|
||||
//
|
||||
// class p1.c1 defined in m1 tries to access p2.c2 defined in m2
|
||||
// Access denied since although m1 can read m2, p2 is exported only to m3.
|
||||
// class p1.c1 defined in m1x tries to access p2.c2 defined in m2x
|
||||
// Access denied since although m1x can read m2x, p2 is exported only to m3x.
|
||||
//
|
||||
public class Umod_ExpQualOther {
|
||||
|
||||
@ -64,63 +64,63 @@ public class Umod_ExpQualOther {
|
||||
// publically defined classes within packages of those modules.
|
||||
public void createLayerOnBoot() throws Throwable {
|
||||
|
||||
// Define module: m1 (need to define m1 to establish the Layer successfully)
|
||||
// Can read: java.base, m2, m3
|
||||
// Define module: m1x (need to define m1x to establish the Layer successfully)
|
||||
// Can read: java.base, m2x, m3x
|
||||
// Packages: none
|
||||
// Packages exported: none
|
||||
ModuleDescriptor descriptor_m1 =
|
||||
ModuleDescriptor.module("m1")
|
||||
ModuleDescriptor descriptor_m1x =
|
||||
ModuleDescriptor.newModule("m1x")
|
||||
.requires("java.base")
|
||||
.requires("m2")
|
||||
.requires("m3")
|
||||
.requires("m2x")
|
||||
.requires("m3x")
|
||||
.build();
|
||||
|
||||
// Define module: m2
|
||||
// Define module: m2x
|
||||
// Can read: java.base
|
||||
// Packages: p2
|
||||
// Packages exported: p2 is exported to m3
|
||||
ModuleDescriptor descriptor_m2 =
|
||||
ModuleDescriptor.module("m2")
|
||||
// Packages exported: p2 is exported to m3x
|
||||
ModuleDescriptor descriptor_m2x =
|
||||
ModuleDescriptor.newModule("m2x")
|
||||
.requires("java.base")
|
||||
.exports("p2", Set.of("m3"))
|
||||
.exports("p2", Set.of("m3x"))
|
||||
.build();
|
||||
|
||||
// Define module: m3
|
||||
// Define module: m3x
|
||||
// Can read: java.base
|
||||
// Packages: p3
|
||||
// Packages exported: none
|
||||
ModuleDescriptor descriptor_m3 =
|
||||
ModuleDescriptor.module("m3")
|
||||
ModuleDescriptor descriptor_m3x =
|
||||
ModuleDescriptor.newModule("m3x")
|
||||
.requires("java.base")
|
||||
.build();
|
||||
|
||||
// Set up a ModuleFinder containing all modules for this layer.
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1, descriptor_m2, descriptor_m3);
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1x, descriptor_m2x, descriptor_m3x);
|
||||
|
||||
// Resolves "m1"
|
||||
// Resolves "m1x"
|
||||
Configuration cf = Layer.boot()
|
||||
.configuration()
|
||||
.resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
|
||||
.resolve(finder, ModuleFinder.of(), Set.of("m1x"));
|
||||
|
||||
// map each module to differing class loaders for this test
|
||||
Map<String, ClassLoader> map = new HashMap<>();
|
||||
map.put("m1", MySameClassLoader.loader1);
|
||||
map.put("m2", MySameClassLoader.loader1);
|
||||
map.put("m3", MySameClassLoader.loader1);
|
||||
map.put("m1x", MySameClassLoader.loader1);
|
||||
map.put("m2x", MySameClassLoader.loader1);
|
||||
map.put("m3x", MySameClassLoader.loader1);
|
||||
|
||||
// Create Layer that contains m1, m2 and m3
|
||||
// Create Layer that contains m1x, m2x and m3x
|
||||
Layer layer = Layer.boot().defineModules(cf, map::get);
|
||||
|
||||
assertTrue(layer.findLoader("m1") == MySameClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m2") == MySameClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m3") == MySameClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m1x") == MySameClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m2x") == MySameClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m3x") == MySameClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("java.base") == null);
|
||||
|
||||
// now use the same loader to load class p1.c1
|
||||
Class p1_c1_class = MySameClassLoader.loader1.loadClass("p1.c1");
|
||||
try {
|
||||
p1_c1_class.newInstance();
|
||||
throw new RuntimeException("Failed to get IAE (p2 in m2 is exported to m3, not unqualifiedly to everyone)");
|
||||
throw new RuntimeException("Failed to get IAE (p2 in m2x is exported to m3x, not unqualifiedly to everyone)");
|
||||
} catch (IllegalAccessError e) {
|
||||
System.out.println(e.getMessage());
|
||||
if (!e.getMessage().contains("does not export")) {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -25,8 +25,8 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Test if package p2 in module m2 is exported unqualifiedly,
|
||||
* then class p1.c1 in an unnamed module can read p2.c2 in module m2.
|
||||
* @summary Test if package p2 in module m2x is exported unqualifiedly,
|
||||
* then class p1.c1 in an unnamed module can read p2.c2 in module m2x.
|
||||
* @modules java.base/jdk.internal.misc
|
||||
* @library /test/lib
|
||||
* @compile myloaders/MySameClassLoader.java
|
||||
@ -47,15 +47,15 @@ import java.util.Set;
|
||||
import myloaders.MySameClassLoader;
|
||||
|
||||
//
|
||||
// ClassLoader1 --> defines m1 --> no packages
|
||||
// defines m2 --> packages p2
|
||||
// ClassLoader1 --> defines m1x --> no packages
|
||||
// defines m2x --> packages p2
|
||||
//
|
||||
// m1 can read m2
|
||||
// package p2 in m2 is exported unqualifiedly
|
||||
// m1x can read m2x
|
||||
// package p2 in m2x is exported unqualifiedly
|
||||
//
|
||||
// class p1.c1 defined in an unnamed module tries to access p2.c2 defined in m2
|
||||
// class p1.c1 defined in an unnamed module tries to access p2.c2 defined in m2x
|
||||
// Access allowed, an unnamed module can read all modules and p2 in module
|
||||
// m2 which is exported unqualifiedly.
|
||||
// m2x which is exported unqualifiedly.
|
||||
|
||||
public class Umod_ExpUnqual {
|
||||
|
||||
@ -64,44 +64,44 @@ public class Umod_ExpUnqual {
|
||||
// publically defined classes within packages of those modules.
|
||||
public void createLayerOnBoot() throws Throwable {
|
||||
|
||||
// Define module: m1
|
||||
// Can read: java.base, m2
|
||||
// Define module: m1x
|
||||
// Can read: java.base, m2x
|
||||
// Packages: none
|
||||
// Packages exported: none
|
||||
ModuleDescriptor descriptor_m1 =
|
||||
ModuleDescriptor.module("m1")
|
||||
ModuleDescriptor descriptor_m1x =
|
||||
ModuleDescriptor.newModule("m1x")
|
||||
.requires("java.base")
|
||||
.requires("m2")
|
||||
.requires("m2x")
|
||||
.build();
|
||||
|
||||
// Define module: m2
|
||||
// Define module: m2x
|
||||
// Can read: java.base
|
||||
// Packages: p2
|
||||
// Packages exported: p2 is exported unqualifiedly
|
||||
ModuleDescriptor descriptor_m2 =
|
||||
ModuleDescriptor.module("m2")
|
||||
ModuleDescriptor descriptor_m2x =
|
||||
ModuleDescriptor.newModule("m2x")
|
||||
.requires("java.base")
|
||||
.exports("p2")
|
||||
.build();
|
||||
|
||||
// Set up a ModuleFinder containing all modules for this layer.
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1, descriptor_m2);
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1x, descriptor_m2x);
|
||||
|
||||
// Resolves "m1"
|
||||
// Resolves "m1x"
|
||||
Configuration cf = Layer.boot()
|
||||
.configuration()
|
||||
.resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
|
||||
.resolve(finder, ModuleFinder.of(), Set.of("m1x"));
|
||||
|
||||
// map each module to differing class loaders for this test
|
||||
Map<String, ClassLoader> map = new HashMap<>();
|
||||
map.put("m1", MySameClassLoader.loader1);
|
||||
map.put("m2", MySameClassLoader.loader1);
|
||||
map.put("m1x", MySameClassLoader.loader1);
|
||||
map.put("m2x", MySameClassLoader.loader1);
|
||||
|
||||
// Create Layer that contains m1 & m2
|
||||
// Create Layer that contains m1x & m2x
|
||||
Layer layer = Layer.boot().defineModules(cf, map::get);
|
||||
|
||||
assertTrue(layer.findLoader("m1") == MySameClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m2") == MySameClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m1x") == MySameClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m2x") == MySameClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("java.base") == null);
|
||||
|
||||
// now use the same loader to load class p1.c1
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -25,8 +25,8 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Test if package p2 in module m2 is not exported, then class p1.c1
|
||||
* in an unnamed module can not access p2.c2 in module m2.
|
||||
* @summary Test if package p2 in module m2x is not exported, then class p1.c1
|
||||
* in an unnamed module can not access p2.c2 in module m2x.
|
||||
* @modules java.base/jdk.internal.misc
|
||||
* @library /test/lib
|
||||
* @compile myloaders/MySameClassLoader.java
|
||||
@ -46,13 +46,13 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import myloaders.MySameClassLoader;
|
||||
|
||||
// ClassLoader1 --> defines m1 --> no packages
|
||||
// defines m2 --> packages p2
|
||||
// ClassLoader1 --> defines m1x --> no packages
|
||||
// defines m2x --> packages p2
|
||||
//
|
||||
// m1 can read m2
|
||||
// package p2 in m2 is not exported
|
||||
// m1x can read m2x
|
||||
// package p2 in m2x is not exported
|
||||
//
|
||||
// class p1.c1 defined in an unnamed module tries to access p2.c2 defined in m2
|
||||
// class p1.c1 defined in an unnamed module tries to access p2.c2 defined in m2x
|
||||
// Access denied since p2 is not exported.
|
||||
//
|
||||
public class Umod_PkgNotExp {
|
||||
@ -62,51 +62,51 @@ public class Umod_PkgNotExp {
|
||||
// publically defined classes within packages of those modules.
|
||||
public void createLayerOnBoot() throws Throwable {
|
||||
|
||||
// Define module: m1
|
||||
// Can read: java.base, m2
|
||||
// Define module: m1x
|
||||
// Can read: java.base, m2x
|
||||
// Packages: none
|
||||
// Packages exported: none
|
||||
ModuleDescriptor descriptor_m1 =
|
||||
ModuleDescriptor.module("m1")
|
||||
ModuleDescriptor descriptor_m1x =
|
||||
ModuleDescriptor.newModule("m1x")
|
||||
.requires("java.base")
|
||||
.requires("m2")
|
||||
.requires("m2x")
|
||||
.build();
|
||||
|
||||
// Define module: m2
|
||||
// Define module: m2x
|
||||
// Can read: java.base
|
||||
// Packages: p2
|
||||
// Packages exported: none
|
||||
ModuleDescriptor descriptor_m2 =
|
||||
ModuleDescriptor.module("m2")
|
||||
ModuleDescriptor descriptor_m2x =
|
||||
ModuleDescriptor.newModule("m2x")
|
||||
.requires("java.base")
|
||||
.contains("p2")
|
||||
.packages(Set.of("p2"))
|
||||
.build();
|
||||
|
||||
// Set up a ModuleFinder containing all modules for this layer.
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1, descriptor_m2);
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1x, descriptor_m2x);
|
||||
|
||||
// Resolves "m1"
|
||||
// Resolves "m1x"
|
||||
Configuration cf = Layer.boot()
|
||||
.configuration()
|
||||
.resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
|
||||
.resolve(finder, ModuleFinder.of(), Set.of("m1x"));
|
||||
|
||||
// map each module to the same class loader for this test
|
||||
Map<String, ClassLoader> map = new HashMap<>();
|
||||
map.put("m1", MySameClassLoader.loader1);
|
||||
map.put("m2", MySameClassLoader.loader1);
|
||||
map.put("m1x", MySameClassLoader.loader1);
|
||||
map.put("m2x", MySameClassLoader.loader1);
|
||||
|
||||
// Create Layer that contains m1 and m2
|
||||
// Create Layer that contains m1x and m2x
|
||||
Layer layer = Layer.boot().defineModules(cf, map::get);
|
||||
|
||||
assertTrue(layer.findLoader("m1") == MySameClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m2") == MySameClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m1x") == MySameClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("m2x") == MySameClassLoader.loader1);
|
||||
assertTrue(layer.findLoader("java.base") == null);
|
||||
|
||||
// now use the same loader to load class p1.c1
|
||||
Class p1_c1_class = MySameClassLoader.loader1.loadClass("p1.c1");
|
||||
try {
|
||||
p1_c1_class.newInstance();
|
||||
throw new RuntimeException("Failed to get IAE (p2 in m2 is not exported)");
|
||||
throw new RuntimeException("Failed to get IAE (p2 in m2x is not exported)");
|
||||
} catch (IllegalAccessError e) {
|
||||
System.out.println(e.getMessage());
|
||||
if (!e.getMessage().contains("does not export")) {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -26,7 +26,7 @@ import p2.c2;
|
||||
|
||||
public class c1Loose {
|
||||
public c1Loose() {
|
||||
// Attempt access - access should succeed since m1 is a loose module
|
||||
// Attempt access - access should succeed since m1x is a loose module
|
||||
p2.c2 c2_obj = new p2.c2();
|
||||
c2_obj.method2();
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -27,12 +27,12 @@ import p2.c2;
|
||||
|
||||
public class c1ReadEdge {
|
||||
public c1ReadEdge() {
|
||||
// Establish read edge from module m1, where c1ReadEdge is defined,
|
||||
// Establish read edge from module m1x, where c1ReadEdge is defined,
|
||||
// to the unnamed module, where p2.c2 will be defined.
|
||||
Module m1 = c1ReadEdge.class.getModule();
|
||||
Module m1x = c1ReadEdge.class.getModule();
|
||||
ClassLoader loader = c1ReadEdge.class.getClassLoader();
|
||||
Module unnamed_module = loader.getUnnamedModule();
|
||||
m1.addReads(unnamed_module);
|
||||
m1x.addReads(unnamed_module);
|
||||
|
||||
// Attempt access - access should succeed
|
||||
p2.c2 c2_obj = new p2.c2();
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -28,32 +28,32 @@ import p2.c2;
|
||||
|
||||
public class c1ReadEdgeDiffLoader {
|
||||
public c1ReadEdgeDiffLoader() {
|
||||
// The goal is to establish a read edge between module m1
|
||||
// The goal is to establish a read edge between module m1x
|
||||
// which is the module where p1.c1ReadEdgeDiffLoader is defined,
|
||||
// and the unnamed module that defines p2.c2. This must be
|
||||
// done in 2 steps:
|
||||
//
|
||||
// Step #1: Establish a read edge between m1, where c1ReadEdgeDiffLoader
|
||||
// Step #1: Establish a read edge between m1x, where c1ReadEdgeDiffLoader
|
||||
// is defined, and the System ClassLoader's unnamed module,
|
||||
// where MyDiffClassLoader is defined. This read edge
|
||||
// is needed before we can obtain MyDiffClassLoader.loader2's unnamed module.
|
||||
//
|
||||
// Step #2: Establish a read edge between m1, where c1ReadEdgeDiffLoader
|
||||
// Step #2: Establish a read edge between m1x, where c1ReadEdgeDiffLoader
|
||||
// is defined, and the MyDiffClassLoader.loader2's unnamed module,
|
||||
// where p2.c2 will be defined.
|
||||
|
||||
// Step #1: read edge m1 -> System ClassLoader's unnamed module
|
||||
Module m1 = c1ReadEdgeDiffLoader.class.getModule();
|
||||
// Step #1: read edge m1x -> System ClassLoader's unnamed module
|
||||
Module m1x = c1ReadEdgeDiffLoader.class.getModule();
|
||||
ClassLoader system_loader = ClassLoader.getSystemClassLoader();
|
||||
Module unnamed_module1 = system_loader.getUnnamedModule();
|
||||
m1.addReads(unnamed_module1);
|
||||
Module unnamed_module_one = system_loader.getUnnamedModule();
|
||||
m1x.addReads(unnamed_module_one);
|
||||
|
||||
// Step #2: read edge m1 -> MyDiffClassLoader.loader2's unnamed module
|
||||
// Step #2: read edge m1x -> MyDiffClassLoader.loader2's unnamed module
|
||||
ClassLoader loader2 = MyDiffClassLoader.loader2;
|
||||
Module unnamed_module2 = loader2.getUnnamedModule();
|
||||
m1.addReads(unnamed_module2);
|
||||
Module unnamed_module_two = loader2.getUnnamedModule();
|
||||
m1x.addReads(unnamed_module_two);
|
||||
|
||||
// Attempt access - access should succeed since m1 can read
|
||||
// Attempt access - access should succeed since m1x can read
|
||||
// MyDiffClassLoader.loader2's unnamed module
|
||||
p2.c2 c2_obj = new p2.c2();
|
||||
c2_obj.method2();
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -26,12 +26,12 @@
|
||||
* import java.lang.reflect.*;
|
||||
* public class c3ReadEdge {
|
||||
* public c3ReadEdge() {
|
||||
* // Establish read edge from module m1, where c3ReadEdge is defined,
|
||||
* // Establish read edge from module m1x, where c3ReadEdge is defined,
|
||||
* // to the unnamed module, where c4 will be defined.
|
||||
* Module m1 = c3ReadEdge.class.getModule();
|
||||
* Module m1x = c3ReadEdge.class.getModule();
|
||||
* ClassLoader loader = c3ReadEdge.class.getClassLoader();
|
||||
* Module unnamed_module = loader.getUnnamedModule();
|
||||
* m1.addReads(unnamed_module);
|
||||
* m1x.addReads(unnamed_module);
|
||||
* // Attempt access - access should succeed
|
||||
* c4 c4_obj = new c4();
|
||||
* c4_obj.method4();
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -28,32 +28,32 @@
|
||||
*
|
||||
* public class c3ReadEdgeDiffLoader {
|
||||
* public c3ReadEdgeDiffLoader() {
|
||||
* // The goal is to establish a read edge between module m1
|
||||
* // The goal is to establish a read edge between module m1x
|
||||
* // which is the module where p3.c3ReadEdgeDiffLoader is defined,
|
||||
* // and the unnamed module that defines c4. This must be
|
||||
* // done in 2 steps:
|
||||
* //
|
||||
* // Step #1: Establish a read edge between m1, where c3ReadEdgeDiffLoader
|
||||
* // Step #1: Establish a read edge between m1x, where c3ReadEdgeDiffLoader
|
||||
* // is defined, and the System ClassLoader's unnamed module,
|
||||
* // where MyDiffClassLoader is defined. This read edge
|
||||
* // is needed before we can obtain MyDiffClassLoader.loader2's unnamed module.
|
||||
* //
|
||||
* // Step #2: Establish a read edge between m1, where c3ReadEdgeDiffLoader
|
||||
* // Step #2: Establish a read edge between m1x, where c3ReadEdgeDiffLoader
|
||||
* // is defined, and the MyDiffClassLoader.loader2's unnamed module,
|
||||
* // where c4 will be defined.
|
||||
*
|
||||
* // Step #1: read edge m1 -> System ClassLoader's unnamed module
|
||||
* Module m1 = c3ReadEdgeDiffLoader.class.getModule();
|
||||
* // Step #1: read edge m1x -> System ClassLoader's unnamed module
|
||||
* Module m1x = c3ReadEdgeDiffLoader.class.getModule();
|
||||
* ClassLoader system_loader = ClassLoader.getSystemClassLoader();
|
||||
* Module unnamed_module1 = system_loader.getUnnamedModule();
|
||||
* m1.addReads(unnamed_module1);
|
||||
* Module unnamed_module_one = system_loader.getUnnamedModule();
|
||||
* m1x.addReads(unnamed_module_one);
|
||||
*
|
||||
* // Step #2: read edge m1 -> MyDiffClassLoader.loader2's unnamed module
|
||||
* // Step #2: read edge m1x -> MyDiffClassLoader.loader2's unnamed module
|
||||
* ClassLoader loader2 = MyDiffClassLoader.loader2;
|
||||
* Module unnamed_module2 = loader2.getUnnamedModule();
|
||||
* m1.addReads(unnamed_module2);
|
||||
* Module unnamed_module_two = loader2.getUnnamedModule();
|
||||
* m1x.addReads(unnamed_module_two);
|
||||
*
|
||||
* // Attempt access - should succeed since m1 can read
|
||||
* // Attempt access - should succeed since m1x can read
|
||||
* // MyDiffClassLoader.loader2's unnamed module
|
||||
* c4 c4_obj = new c4();
|
||||
* c4_obj.method4();
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -43,7 +43,7 @@ public class AccessCheckAllUnnamed {
|
||||
// and then test that a class in the unnamed module can access a package in a
|
||||
// named module that has been exported to all unnamed modules.
|
||||
public static void main(String args[]) throws Throwable {
|
||||
Object m1, m2;
|
||||
Object m1x, m2x;
|
||||
|
||||
// Get the java.lang.reflect.Module object for module java.base.
|
||||
Class jlObject = Class.forName("java.lang.Object");
|
||||
@ -55,16 +55,16 @@ public class AccessCheckAllUnnamed {
|
||||
ClassLoader this_cldr = AccessCheckAllUnnamed.class.getClassLoader();
|
||||
|
||||
// Define a module for p3.
|
||||
m1 = ModuleHelper.ModuleObject("module1", this_cldr, new String[] { "p3" });
|
||||
assertNotNull(m1, "Module should not be null");
|
||||
ModuleHelper.DefineModule(m1, "9.0", "m1/there", new String[] { "p3" });
|
||||
ModuleHelper.AddReadsModule(m1, jlObject_jlrM);
|
||||
m1x = ModuleHelper.ModuleObject("module_one", this_cldr, new String[] { "p3" });
|
||||
assertNotNull(m1x, "Module should not be null");
|
||||
ModuleHelper.DefineModule(m1x, "9.0", "m1x/there", new String[] { "p3" });
|
||||
ModuleHelper.AddReadsModule(m1x, jlObject_jlrM);
|
||||
|
||||
// Define a module for p2.
|
||||
m2 = ModuleHelper.ModuleObject("module2", this_cldr, new String[] { "p2" });
|
||||
assertNotNull(m2, "Module should not be null");
|
||||
ModuleHelper.DefineModule(m2, "9.0", "m2/there", new String[] { "p2" });
|
||||
ModuleHelper.AddReadsModule(m2, jlObject_jlrM);
|
||||
m2x = ModuleHelper.ModuleObject("module_two", this_cldr, new String[] { "p2" });
|
||||
assertNotNull(m2x, "Module should not be null");
|
||||
ModuleHelper.DefineModule(m2x, "9.0", "m2x/there", new String[] { "p2" });
|
||||
ModuleHelper.AddReadsModule(m2x, jlObject_jlrM);
|
||||
|
||||
try {
|
||||
ModuleHelper.AddModuleExportsToAllUnnamed((Module)null, "p2");
|
||||
@ -74,7 +74,7 @@ public class AccessCheckAllUnnamed {
|
||||
}
|
||||
|
||||
try {
|
||||
ModuleHelper.AddModuleExportsToAllUnnamed(m2, null);
|
||||
ModuleHelper.AddModuleExportsToAllUnnamed(m2x, null);
|
||||
throw new RuntimeException("Failed to get the expected NPE for null package");
|
||||
} catch(NullPointerException e) {
|
||||
// Expected
|
||||
@ -88,21 +88,21 @@ public class AccessCheckAllUnnamed {
|
||||
}
|
||||
|
||||
try {
|
||||
ModuleHelper.AddModuleExportsToAllUnnamed(m2, "p3");
|
||||
ModuleHelper.AddModuleExportsToAllUnnamed(m2x, "p3");
|
||||
throw new RuntimeException("Failed to get the expected IAE for package in other module");
|
||||
} catch(IllegalArgumentException e) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
try {
|
||||
ModuleHelper.AddModuleExportsToAllUnnamed(m2, "p4");
|
||||
ModuleHelper.AddModuleExportsToAllUnnamed(m2x, "p4");
|
||||
throw new RuntimeException("Failed to get the expected IAE for package not in module");
|
||||
} catch(IllegalArgumentException e) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
// Export package p2 in m2 to allUnnamed.
|
||||
ModuleHelper.AddModuleExportsToAllUnnamed(m2, "p2");
|
||||
// Export package p2 in m2x to allUnnamed.
|
||||
ModuleHelper.AddModuleExportsToAllUnnamed(m2x, "p2");
|
||||
|
||||
// p1.c1's ctor tries to call a method in p2.c2. This should succeed because
|
||||
// p1 is in an unnamed module and p2.c2 is exported to all unnamed modules.
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -39,10 +39,10 @@ import static jdk.test.lib.Asserts.*;
|
||||
|
||||
public class AccessCheckExp {
|
||||
|
||||
// Test that if module1 can read module2, but package p2 in module2 is not
|
||||
// exported then class p1.c1 in module1 can not read p2.c2 in module2.
|
||||
// Test that if module_one can read module_two, but package p2 in module_two is not
|
||||
// exported then class p1.c1 in module_one can not read p2.c2 in module_two.
|
||||
public static void main(String args[]) throws Throwable {
|
||||
Object m1, m2;
|
||||
Object m1x, m2x;
|
||||
|
||||
// Get the java.lang.reflect.Module object for module java.base.
|
||||
Class jlObject = Class.forName("java.lang.Object");
|
||||
@ -54,28 +54,28 @@ public class AccessCheckExp {
|
||||
ClassLoader this_cldr = AccessCheckExp.class.getClassLoader();
|
||||
|
||||
// Define a module for p1.
|
||||
m1 = ModuleHelper.ModuleObject("module1", this_cldr, new String[] { "p1" });
|
||||
assertNotNull(m1, "Module should not be null");
|
||||
ModuleHelper.DefineModule(m1, "9.0", "m1/here", new String[] { "p1" });
|
||||
ModuleHelper.AddReadsModule(m1, jlObject_jlrM);
|
||||
m1x = ModuleHelper.ModuleObject("module_one", this_cldr, new String[] { "p1" });
|
||||
assertNotNull(m1x, "Module should not be null");
|
||||
ModuleHelper.DefineModule(m1x, "9.0", "m1x/here", new String[] { "p1" });
|
||||
ModuleHelper.AddReadsModule(m1x, jlObject_jlrM);
|
||||
|
||||
// Define a module for p2.
|
||||
m2 = ModuleHelper.ModuleObject("module2", this_cldr, new String[] { "p2" });
|
||||
assertNotNull(m2, "Module should not be null");
|
||||
ModuleHelper.DefineModule(m2, "9.0", "m2/there", new String[] { "p2" });
|
||||
ModuleHelper.AddReadsModule(m2, jlObject_jlrM);
|
||||
m2x = ModuleHelper.ModuleObject("module_two", this_cldr, new String[] { "p2" });
|
||||
assertNotNull(m2x, "Module should not be null");
|
||||
ModuleHelper.DefineModule(m2x, "9.0", "m2x/there", new String[] { "p2" });
|
||||
ModuleHelper.AddReadsModule(m2x, jlObject_jlrM);
|
||||
|
||||
// Make package p1 in m1 visible to everyone.
|
||||
ModuleHelper.AddModuleExportsToAll(m1, "p1");
|
||||
// Make package p1 in m1x visible to everyone.
|
||||
ModuleHelper.AddModuleExportsToAll(m1x, "p1");
|
||||
|
||||
// p1.c1's ctor tries to call a method in p2.c2, but p2.c2 is not
|
||||
// exported. So should get IllegalAccessError.
|
||||
ModuleHelper.AddReadsModule(m1, m2);
|
||||
ModuleHelper.AddReadsModule(m1x, m2x);
|
||||
|
||||
Class p1_c1_class = Class.forName("p1.c1");
|
||||
try {
|
||||
p1_c1_class.newInstance();
|
||||
throw new RuntimeException("Failed to get IAE (p2 in m2 is not exported");
|
||||
throw new RuntimeException("Failed to get IAE (p2 in m2x is not exported");
|
||||
} catch (IllegalAccessError f) {
|
||||
System.out.println(f.getMessage());
|
||||
if (!f.getMessage().contains("does not export")) {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -38,16 +38,16 @@ import static jdk.test.lib.Asserts.*;
|
||||
|
||||
public class AccessCheckJavaBase {
|
||||
|
||||
// Test that a class defined to module2 always can read java.base.
|
||||
// Test that a class defined to module_two always can read java.base.
|
||||
public static void main(String args[]) throws Throwable {
|
||||
// Get the class loader for AccessCheckJavaBase and assume it's also used to
|
||||
// load class p2.c2.
|
||||
ClassLoader this_cldr = AccessCheckJavaBase.class.getClassLoader();
|
||||
|
||||
// Define a module for p2.
|
||||
Object m2 = ModuleHelper.ModuleObject("module2", this_cldr, new String[] { "p2" });
|
||||
assertNotNull(m2, "Module should not be null");
|
||||
ModuleHelper.DefineModule(m2, "9.0", "m2/there", new String[] { "p2" });
|
||||
Object m2x = ModuleHelper.ModuleObject("module_two", this_cldr, new String[] { "p2" });
|
||||
assertNotNull(m2x, "Module should not be null");
|
||||
ModuleHelper.DefineModule(m2x, "9.0", "m2x/there", new String[] { "p2" });
|
||||
|
||||
// p2.c2 can read its superclass java.lang.Object defined within java.base
|
||||
try {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -39,10 +39,10 @@ import static jdk.test.lib.Asserts.*;
|
||||
|
||||
public class AccessCheckRead {
|
||||
|
||||
// Test that a class in a package in module1 cannot access a class in
|
||||
// a package n module2 if module1 cannot read module2.
|
||||
// Test that a class in a package in module_one cannot access a class in
|
||||
// a package in module_two if module_one cannot read module_two.
|
||||
public static void main(String args[]) throws Throwable {
|
||||
Object m1, m2;
|
||||
Object m1x, m2x;
|
||||
|
||||
// Get the java.lang.reflect.Module object for module java.base.
|
||||
Class jlObject = Class.forName("java.lang.Object");
|
||||
@ -54,19 +54,19 @@ public class AccessCheckRead {
|
||||
ClassLoader this_cldr = AccessCheckRead.class.getClassLoader();
|
||||
|
||||
// Define a module for p1.
|
||||
m1 = ModuleHelper.ModuleObject("module1", this_cldr, new String[] { "p1" });
|
||||
assertNotNull(m1, "Module should not be null");
|
||||
ModuleHelper.DefineModule(m1, "9.0", "m1/here", new String[] { "p1" });
|
||||
ModuleHelper.AddReadsModule(m1, jlObject_jlrM);
|
||||
m1x = ModuleHelper.ModuleObject("module_one", this_cldr, new String[] { "p1" });
|
||||
assertNotNull(m1x, "Module should not be null");
|
||||
ModuleHelper.DefineModule(m1x, "9.0", "m1x/here", new String[] { "p1" });
|
||||
ModuleHelper.AddReadsModule(m1x, jlObject_jlrM);
|
||||
|
||||
// Define a module for p2.
|
||||
m2 = ModuleHelper.ModuleObject("module2", this_cldr, new String[] { "p2" });
|
||||
assertNotNull(m2, "Module should not be null");
|
||||
ModuleHelper.DefineModule(m2, "9.0", "m2/there", new String[] { "p2" });
|
||||
ModuleHelper.AddReadsModule(m2, jlObject_jlrM);
|
||||
m2x = ModuleHelper.ModuleObject("module_two", this_cldr, new String[] { "p2" });
|
||||
assertNotNull(m2x, "Module should not be null");
|
||||
ModuleHelper.DefineModule(m2x, "9.0", "m2x/there", new String[] { "p2" });
|
||||
ModuleHelper.AddReadsModule(m2x, jlObject_jlrM);
|
||||
|
||||
// Make package p1 in m1 visible to everyone.
|
||||
ModuleHelper.AddModuleExportsToAll(m1, "p1");
|
||||
// Make package p1 in m1x visible to everyone.
|
||||
ModuleHelper.AddModuleExportsToAll(m1x, "p1");
|
||||
|
||||
Class p1_c1_class = Class.forName("p1.c1");
|
||||
|
||||
@ -74,7 +74,7 @@ public class AccessCheckRead {
|
||||
// cannot read p2's module. So should get IllegalAccessError.
|
||||
try {
|
||||
p1_c1_class.newInstance();
|
||||
throw new RuntimeException("Failed to get IAE (m1 can't read m2)");
|
||||
throw new RuntimeException("Failed to get IAE (m1x can't read m2x)");
|
||||
} catch (IllegalAccessError e) {
|
||||
System.out.println(e.getMessage());
|
||||
if (!e.getMessage().contains("does not read") ||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -48,17 +48,17 @@ public class AccessCheckSuper {
|
||||
ClassLoader this_cldr = AccessCheckSuper.class.getClassLoader();
|
||||
|
||||
// Define a module for p2.
|
||||
Object m2 = ModuleHelper.ModuleObject("module2", this_cldr, new String[] { "p2" });
|
||||
assertNotNull(m2, "Module should not be null");
|
||||
ModuleHelper.DefineModule(m2, "9.0", "m2/there", new String[] { "p2" });
|
||||
Object m2x = ModuleHelper.ModuleObject("module_two", this_cldr, new String[] { "p2" });
|
||||
assertNotNull(m2x, "Module should not be null");
|
||||
ModuleHelper.DefineModule(m2x, "9.0", "m2x/there", new String[] { "p2" });
|
||||
|
||||
// Define a module for p3.
|
||||
Object m3 = ModuleHelper.ModuleObject("module3", this_cldr, new String[] { "p3" });
|
||||
assertNotNull(m3, "Module should not be null");
|
||||
ModuleHelper.DefineModule(m3, "9.0", "m3/there", new String[] { "p3" });
|
||||
Object m3x = ModuleHelper.ModuleObject("module_three", this_cldr, new String[] { "p3" });
|
||||
assertNotNull(m3x, "Module should not be null");
|
||||
ModuleHelper.DefineModule(m3x, "9.0", "m3x/there", new String[] { "p3" });
|
||||
|
||||
// Since a readability edge has not been established between module2
|
||||
// and module3, p3.c3 cannot read its superclass p2.c2.
|
||||
// Since a readability edge has not been established between module_two
|
||||
// and module_three, p3.c3 cannot read its superclass p2.c2.
|
||||
try {
|
||||
Class p3_c3_class = Class.forName("p3.c3");
|
||||
throw new RuntimeException("Failed to get IAE (can't read superclass)");
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -42,7 +42,7 @@ public class AccessCheckUnnamed {
|
||||
// Test that a class in the unnamed module can not access a package in a
|
||||
// named module that has not been unqualifiedly exported.
|
||||
public static void main(String args[]) throws Throwable {
|
||||
Object m1, m2;
|
||||
Object m1x, m2x;
|
||||
|
||||
// Get the java.lang.reflect.Module object for module java.base.
|
||||
Class jlObject = Class.forName("java.lang.Object");
|
||||
@ -54,17 +54,17 @@ public class AccessCheckUnnamed {
|
||||
ClassLoader this_cldr = AccessCheckUnnamed.class.getClassLoader();
|
||||
|
||||
// Define a module for p2.
|
||||
m2 = ModuleHelper.ModuleObject("module2", this_cldr, new String[] { "p2" });
|
||||
assertNotNull(m2, "Module should not be null");
|
||||
ModuleHelper.DefineModule(m2, "9.0", "m2/there", new String[] { "p2" });
|
||||
ModuleHelper.AddReadsModule(m2, jlObject_jlrM);
|
||||
m2x = ModuleHelper.ModuleObject("module_two", this_cldr, new String[] { "p2" });
|
||||
assertNotNull(m2x, "Module should not be null");
|
||||
ModuleHelper.DefineModule(m2x, "9.0", "m2x/there", new String[] { "p2" });
|
||||
ModuleHelper.AddReadsModule(m2x, jlObject_jlrM);
|
||||
|
||||
// p1.c1's ctor tries to call a method in p2.c2. This should fail because
|
||||
// p1 is in the unnamed module and p2.c2 is not unqualifiedly exported.
|
||||
Class p1_c1_class = Class.forName("p1.c1");
|
||||
try {
|
||||
Object c1_obj = p1_c1_class.newInstance();
|
||||
throw new RuntimeException("Failed to get IAE (p2 in m2 is not exported to unnamed module)");
|
||||
throw new RuntimeException("Failed to get IAE (p2 in m2x is not exported to unnamed module)");
|
||||
} catch (IllegalAccessError f) {
|
||||
System.out.println(f.getMessage());
|
||||
if (!f.getMessage().contains("does not export p2 to unnamed module")) {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -39,11 +39,11 @@ import static jdk.test.lib.Asserts.*;
|
||||
|
||||
public class AccessCheckWorks {
|
||||
|
||||
// Check that a class in a package in module1 can successfully access a
|
||||
// class in module2 when module1 can read module2 and the class's package
|
||||
// Check that a class in a package in module_one can successfully access a
|
||||
// class in module_two when module_one can read module_two and the class's package
|
||||
// has been exported.
|
||||
public static void main(String args[]) throws Throwable {
|
||||
Object m1, m2;
|
||||
Object m1x, m2x;
|
||||
|
||||
// Get the java.lang.reflect.Module object for module java.base.
|
||||
Class jlObject = Class.forName("java.lang.Object");
|
||||
@ -55,24 +55,24 @@ public class AccessCheckWorks {
|
||||
ClassLoader this_cldr = AccessCheckWorks.class.getClassLoader();
|
||||
|
||||
// Define a module for p1.
|
||||
m1 = ModuleHelper.ModuleObject("module1", this_cldr, new String[] { "p1" });
|
||||
assertNotNull(m1, "Module should not be null");
|
||||
ModuleHelper.DefineModule(m1, "9.0", "m1/here", new String[] { "p1" });
|
||||
ModuleHelper.AddReadsModule(m1, jlObject_jlrM);
|
||||
m1x = ModuleHelper.ModuleObject("module_one", this_cldr, new String[] { "p1" });
|
||||
assertNotNull(m1x, "Module should not be null");
|
||||
ModuleHelper.DefineModule(m1x, "9.0", "m1x/here", new String[] { "p1" });
|
||||
ModuleHelper.AddReadsModule(m1x, jlObject_jlrM);
|
||||
|
||||
// Define a module for p2.
|
||||
m2 = ModuleHelper.ModuleObject("module2", this_cldr, new String[] { "p2" });
|
||||
assertNotNull(m2, "Module should not be null");
|
||||
ModuleHelper.DefineModule(m2, "9.0", "m2/there", new String[] { "p2" });
|
||||
ModuleHelper.AddReadsModule(m2, jlObject_jlrM);
|
||||
m2x = ModuleHelper.ModuleObject("module_two", this_cldr, new String[] { "p2" });
|
||||
assertNotNull(m2x, "Module should not be null");
|
||||
ModuleHelper.DefineModule(m2x, "9.0", "m2x/there", new String[] { "p2" });
|
||||
ModuleHelper.AddReadsModule(m2x, jlObject_jlrM);
|
||||
|
||||
// Make package p1 in m1 visible to everyone.
|
||||
ModuleHelper.AddModuleExportsToAll(m1, "p1");
|
||||
// Make package p1 in m1x visible to everyone.
|
||||
ModuleHelper.AddModuleExportsToAll(m1x, "p1");
|
||||
|
||||
// p1.c1's ctor tries to call a method in p2.c2. This should work because
|
||||
// p1's module can read p2's module and p2 is exported to p1's module.
|
||||
ModuleHelper.AddReadsModule(m1, m2);
|
||||
ModuleHelper.AddModuleExports(m2, "p2", m1);
|
||||
ModuleHelper.AddReadsModule(m1x, m2x);
|
||||
ModuleHelper.AddModuleExports(m2x, "p2", m1x);
|
||||
Class p1_c1_class = Class.forName("p1.c1");
|
||||
p1_c1_class.newInstance();
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -83,21 +83,21 @@ public class CCE_module_msg {
|
||||
ClassLoader this_cldr = CCE_module_msg.class.getClassLoader();
|
||||
|
||||
// Define a module for p2.
|
||||
Object m2 = ModuleHelper.ModuleObject("module2", this_cldr, new String[] { "p2" });
|
||||
assertNotNull(m2, "Module should not be null");
|
||||
ModuleHelper.DefineModule(m2, "9.0", "m2/there", new String[] { "p2" });
|
||||
ModuleHelper.AddReadsModule(m2, jlObject_jlrM);
|
||||
Object m2x = ModuleHelper.ModuleObject("module_two", this_cldr, new String[] { "p2" });
|
||||
assertNotNull(m2x, "Module should not be null");
|
||||
ModuleHelper.DefineModule(m2x, "9.0", "m2x/there", new String[] { "p2" });
|
||||
ModuleHelper.AddReadsModule(m2x, jlObject_jlrM);
|
||||
|
||||
try {
|
||||
ModuleHelper.AddModuleExportsToAll(m2, "p2");
|
||||
ModuleHelper.AddModuleExportsToAll(m2x, "p2");
|
||||
Object p2Obj = new p2.c2();
|
||||
System.out.println((String)p2Obj);
|
||||
throw new RuntimeException("ClassCastException wasn't thrown, test failed.");
|
||||
} catch (ClassCastException cce) {
|
||||
String exception = cce.getMessage();
|
||||
System.out.println(exception);
|
||||
if (exception.contains("module2/p2.c2") ||
|
||||
!(exception.contains("module2@") &&
|
||||
if (exception.contains("module_two/p2.c2") ||
|
||||
!(exception.contains("module_two@") &&
|
||||
exception.contains("/p2.c2 cannot be cast to java.base/java.lang.String"))) {
|
||||
throw new RuntimeException("Wrong message: " + exception);
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -44,7 +44,7 @@ public class ExportTwice {
|
||||
// Also, check that a package can be exported to a specific package and then
|
||||
// exported unqualifiedly.
|
||||
public static void main(String args[]) throws Throwable {
|
||||
Object m1, m2, m3;
|
||||
Object m1x, m2x, m3x;
|
||||
|
||||
// Get the java.lang.reflect.Module object for module java.base.
|
||||
Class jlObject = Class.forName("java.lang.Object");
|
||||
@ -56,37 +56,37 @@ public class ExportTwice {
|
||||
ClassLoader this_cldr = ExportTwice.class.getClassLoader();
|
||||
|
||||
// Define a module for p1.
|
||||
m1 = ModuleHelper.ModuleObject("module1", this_cldr, new String[] { "p1" });
|
||||
assertNotNull(m1, "Module should not be null");
|
||||
ModuleHelper.DefineModule(m1, "9.0", "m1/here", new String[] { "p1" });
|
||||
ModuleHelper.AddReadsModule(m1, jlObject_jlrM);
|
||||
m1x = ModuleHelper.ModuleObject("module_one", this_cldr, new String[] { "p1" });
|
||||
assertNotNull(m1x, "Module should not be null");
|
||||
ModuleHelper.DefineModule(m1x, "9.0", "m1x/here", new String[] { "p1" });
|
||||
ModuleHelper.AddReadsModule(m1x, jlObject_jlrM);
|
||||
|
||||
// Define a module for p2.
|
||||
m2 = ModuleHelper.ModuleObject("module2", this_cldr, new String[] { "p2" });
|
||||
assertNotNull(m2, "Module should not be null");
|
||||
ModuleHelper.DefineModule(m2, "9.0", "m2/there", new String[] { "p2" });
|
||||
ModuleHelper.AddReadsModule(m2, jlObject_jlrM);
|
||||
m2x = ModuleHelper.ModuleObject("module_two", this_cldr, new String[] { "p2" });
|
||||
assertNotNull(m2x, "Module should not be null");
|
||||
ModuleHelper.DefineModule(m2x, "9.0", "m2x/there", new String[] { "p2" });
|
||||
ModuleHelper.AddReadsModule(m2x, jlObject_jlrM);
|
||||
|
||||
// Define a module for p3.
|
||||
m3 = ModuleHelper.ModuleObject("module3", this_cldr, new String[] { "p3" });
|
||||
assertNotNull(m3, "Module should not be null");
|
||||
ModuleHelper.DefineModule(m3, "9.0", "m3/there", new String[] { "p3" });
|
||||
ModuleHelper.AddReadsModule(m3, jlObject_jlrM);
|
||||
m3x = ModuleHelper.ModuleObject("module_three", this_cldr, new String[] { "p3" });
|
||||
assertNotNull(m3x, "Module should not be null");
|
||||
ModuleHelper.DefineModule(m3x, "9.0", "m3x/there", new String[] { "p3" });
|
||||
ModuleHelper.AddReadsModule(m3x, jlObject_jlrM);
|
||||
|
||||
// Make package p1 in m1 visible to everyone.
|
||||
ModuleHelper.AddModuleExportsToAll(m1, "p1");
|
||||
// Make package p1 in m1x visible to everyone.
|
||||
ModuleHelper.AddModuleExportsToAll(m1x, "p1");
|
||||
|
||||
// Try to export p1 only to m2 after it was exported unqualifiedly. It
|
||||
// Try to export p1 only to m2x after it was exported unqualifiedly. It
|
||||
// should silently succeed.
|
||||
ModuleHelper.AddModuleExports(m1, "p1", m2);
|
||||
ModuleHelper.AddModuleExports(m1x, "p1", m2x);
|
||||
|
||||
// Export p2 to m3 then export it again unqualifiedly.
|
||||
ModuleHelper.AddModuleExports(m2, "p2", m3);
|
||||
ModuleHelper.AddModuleExportsToAll(m2, "p2");
|
||||
// Export p2 to m3x then export it again unqualifiedly.
|
||||
ModuleHelper.AddModuleExports(m2x, "p2", m3x);
|
||||
ModuleHelper.AddModuleExportsToAll(m2x, "p2");
|
||||
|
||||
// p1.c1's ctor tries to call a method in p2.c2. This should work because
|
||||
// p1's module can read p2's module and p2 is now exported unqualifiedly.
|
||||
ModuleHelper.AddReadsModule(m1, m2);
|
||||
ModuleHelper.AddReadsModule(m1x, m2x);
|
||||
Class p1_c1_class = Class.forName("p1.c1");
|
||||
p1_c1_class.newInstance();
|
||||
}
|
||||
|
||||
@ -67,8 +67,8 @@ public class IgnoreModulePropertiesTest {
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
testOption("--add-modules", "java.sqlx", "jdk.module.addmods.0", "java.lang.module.ResolutionException");
|
||||
testOption("--limit-modules", "java.sqlx", "jdk.module.limitmods", "java.lang.module.ResolutionException");
|
||||
testOption("--add-modules", "java.sqlx", "jdk.module.addmods.0", "java.lang.module.FindException");
|
||||
testOption("--limit-modules", "java.sqlx", "jdk.module.limitmods", "java.lang.module.FindException");
|
||||
testOption("--add-reads", "xyzz=yyzd", "jdk.module.addreads.0", "WARNING: Unknown module: xyzz");
|
||||
testOption("--add-exports", "java.base/xyzz=yyzd", "jdk.module.addexports.0",
|
||||
"WARNING: package xyzz not in java.base");
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -39,10 +39,10 @@ import static jdk.test.lib.Asserts.*;
|
||||
|
||||
public class JVMAddModuleExportToAllUnnamed {
|
||||
|
||||
// Check that a class in a package in module1 cannot access a class
|
||||
// Check that a class in a package in module_one cannot access a class
|
||||
// that is in the unnamed module if the accessing package is strict.
|
||||
public static void main(String args[]) throws Throwable {
|
||||
Object m1;
|
||||
Object m1x;
|
||||
|
||||
// Get the java.lang.reflect.Module object for module java.base.
|
||||
Class jlObject = Class.forName("java.lang.Object");
|
||||
@ -54,13 +54,13 @@ public class JVMAddModuleExportToAllUnnamed {
|
||||
ClassLoader this_cldr = JVMAddModuleExportToAllUnnamed.class.getClassLoader();
|
||||
|
||||
// Define a module for p1.
|
||||
m1 = ModuleHelper.ModuleObject("module1", this_cldr, new String[] { "p1" });
|
||||
assertNotNull(m1, "Module should not be null");
|
||||
ModuleHelper.DefineModule(m1, "9.0", "m1/here", new String[] { "p1" });
|
||||
ModuleHelper.AddReadsModule(m1, jlObject_jlrM);
|
||||
m1x = ModuleHelper.ModuleObject("module_one", this_cldr, new String[] { "p1" });
|
||||
assertNotNull(m1x, "Module should not be null");
|
||||
ModuleHelper.DefineModule(m1x, "9.0", "m1x/here", new String[] { "p1" });
|
||||
ModuleHelper.AddReadsModule(m1x, jlObject_jlrM);
|
||||
|
||||
// Make package p1 in m1 visible to everyone.
|
||||
ModuleHelper.AddModuleExportsToAll(m1, "p1");
|
||||
// Make package p1 in m1x visible to everyone.
|
||||
ModuleHelper.AddModuleExportsToAll(m1x, "p1");
|
||||
|
||||
// p1.c1's ctor tries to call a method in p2.c2. This should not work
|
||||
// because p2 is in the unnamed module and p1.c1 is strict.
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -43,7 +43,7 @@ public class JVMAddModuleExportsToAll {
|
||||
// and then test that a class in the unnamed module can access a package in
|
||||
// a named module that has been exported unqualifiedly.
|
||||
public static void main(String args[]) throws Throwable {
|
||||
Object m1, m2, m3;
|
||||
Object m1x, m2x, m3x;
|
||||
|
||||
// Get the java.lang.reflect.Module object for module java.base.
|
||||
Class jlObject = Class.forName("java.lang.Object");
|
||||
@ -55,16 +55,16 @@ public class JVMAddModuleExportsToAll {
|
||||
ClassLoader this_cldr = JVMAddModuleExportsToAll.class.getClassLoader();
|
||||
|
||||
// Define a module for p3.
|
||||
m1 = ModuleHelper.ModuleObject("module1", this_cldr, new String[] { "p3" });
|
||||
assertNotNull(m1, "Module should not be null");
|
||||
ModuleHelper.DefineModule(m1, "9.0", "m1/there", new String[] { "p3" });
|
||||
ModuleHelper.AddReadsModule(m1, jlObject_jlrM);
|
||||
m1x = ModuleHelper.ModuleObject("module_one", this_cldr, new String[] { "p3" });
|
||||
assertNotNull(m1x, "Module should not be null");
|
||||
ModuleHelper.DefineModule(m1x, "9.0", "m1x/there", new String[] { "p3" });
|
||||
ModuleHelper.AddReadsModule(m1x, jlObject_jlrM);
|
||||
|
||||
// Define a module for p2.
|
||||
m2 = ModuleHelper.ModuleObject("module2", this_cldr, new String[] { "p2" });
|
||||
assertNotNull(m2, "Module should not be null");
|
||||
ModuleHelper.DefineModule(m2, "9.0", "m2/there", new String[] { "p2" });
|
||||
ModuleHelper.AddReadsModule(m2, jlObject_jlrM);
|
||||
m2x = ModuleHelper.ModuleObject("module_two", this_cldr, new String[] { "p2" });
|
||||
assertNotNull(m2x, "Module should not be null");
|
||||
ModuleHelper.DefineModule(m2x, "9.0", "m2x/there", new String[] { "p2" });
|
||||
ModuleHelper.AddReadsModule(m2x, jlObject_jlrM);
|
||||
|
||||
try {
|
||||
ModuleHelper.AddModuleExportsToAll((Module)null, "p2");
|
||||
@ -74,7 +74,7 @@ public class JVMAddModuleExportsToAll {
|
||||
}
|
||||
|
||||
try {
|
||||
ModuleHelper.AddModuleExportsToAll(m2, null);
|
||||
ModuleHelper.AddModuleExportsToAll(m2x, null);
|
||||
throw new RuntimeException("Failed to get the expected NPE for null package");
|
||||
} catch(NullPointerException e) {
|
||||
// Expected
|
||||
@ -88,26 +88,26 @@ public class JVMAddModuleExportsToAll {
|
||||
}
|
||||
|
||||
try {
|
||||
ModuleHelper.AddModuleExportsToAll(m2, "p3");
|
||||
ModuleHelper.AddModuleExportsToAll(m2x, "p3");
|
||||
throw new RuntimeException("Failed to get the expected IAE for package that is in another module");
|
||||
} catch(IllegalArgumentException e) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
try {
|
||||
ModuleHelper.AddModuleExportsToAll(m2, "p4");
|
||||
ModuleHelper.AddModuleExportsToAll(m2x, "p4");
|
||||
throw new RuntimeException("Failed to get the expected IAE for package not in any module");
|
||||
} catch(IllegalArgumentException e) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
// Export package p2 in m2 unqualifiedly. Then, do a qualified export
|
||||
// of p2 in m2 to m3. This should not affect the unqualified export.
|
||||
m3 = ModuleHelper.ModuleObject("module3", this_cldr, new String[] { "p4" });
|
||||
assertNotNull(m3, "Module m3 should not be null");
|
||||
ModuleHelper.DefineModule(m3, "9.0", "m3/there", new String[] { "p4" });
|
||||
ModuleHelper.AddModuleExportsToAll(m2, "p2");
|
||||
ModuleHelper.AddModuleExports(m2, "p2", m3);
|
||||
// Export package p2 in m2x unqualifiedly. Then, do a qualified export
|
||||
// of p2 in m2x to m3x. This should not affect the unqualified export.
|
||||
m3x = ModuleHelper.ModuleObject("module_three", this_cldr, new String[] { "p4" });
|
||||
assertNotNull(m3x, "Module m3x should not be null");
|
||||
ModuleHelper.DefineModule(m3x, "9.0", "m3x/there", new String[] { "p4" });
|
||||
ModuleHelper.AddModuleExportsToAll(m2x, "p2");
|
||||
ModuleHelper.AddModuleExports(m2x, "p2", m3x);
|
||||
|
||||
// p1.c1's ctor tries to call a method in p2.c2. This should succeed because
|
||||
// p1 is in an unnamed module and p2.c2 is exported unqualifiedly.
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -40,25 +40,25 @@ public class JVMAddModulePackage {
|
||||
public static void main(String args[]) throws Throwable {
|
||||
MyClassLoader cl1 = new MyClassLoader();
|
||||
MyClassLoader cl3 = new MyClassLoader();
|
||||
Object module1, module2, module3;
|
||||
Object module_one, module_two, module_three;
|
||||
boolean result;
|
||||
|
||||
module1 = ModuleHelper.ModuleObject("module1", cl1, new String[] { "mypackage" });
|
||||
assertNotNull(module1, "Module should not be null");
|
||||
ModuleHelper.DefineModule(module1, "9.0", "module1/here", new String[] { "mypackage" });
|
||||
module2 = ModuleHelper.ModuleObject("module2", cl1, new String[] { "yourpackage" });
|
||||
assertNotNull(module2, "Module should not be null");
|
||||
ModuleHelper.DefineModule(module2, "9.0", "module2/here", new String[] { "yourpackage" });
|
||||
module3 = ModuleHelper.ModuleObject("module3", cl3, new String[] { "package/num3" });
|
||||
assertNotNull(module3, "Module should not be null");
|
||||
ModuleHelper.DefineModule(module3, "9.0", "module3/here", new String[] { "package/num3" });
|
||||
module_one = ModuleHelper.ModuleObject("module_one", cl1, new String[] { "mypackage" });
|
||||
assertNotNull(module_one, "Module should not be null");
|
||||
ModuleHelper.DefineModule(module_one, "9.0", "module_one/here", new String[] { "mypackage" });
|
||||
module_two = ModuleHelper.ModuleObject("module_two", cl1, new String[] { "yourpackage" });
|
||||
assertNotNull(module_two, "Module should not be null");
|
||||
ModuleHelper.DefineModule(module_two, "9.0", "module_two/here", new String[] { "yourpackage" });
|
||||
module_three = ModuleHelper.ModuleObject("module_three", cl3, new String[] { "package/num3" });
|
||||
assertNotNull(module_three, "Module should not be null");
|
||||
ModuleHelper.DefineModule(module_three, "9.0", "module_three/here", new String[] { "package/num3" });
|
||||
|
||||
// Simple call
|
||||
ModuleHelper.AddModulePackage(module1, "new_package");
|
||||
ModuleHelper.AddModulePackage(module_one, "new_package");
|
||||
|
||||
// Add a package and export it
|
||||
ModuleHelper.AddModulePackage(module1, "package/num3");
|
||||
ModuleHelper.AddModuleExportsToAll(module1, "package/num3");
|
||||
ModuleHelper.AddModulePackage(module_one, "package/num3");
|
||||
ModuleHelper.AddModuleExportsToAll(module_one, "package/num3");
|
||||
|
||||
// Null module argument, expect an NPE
|
||||
try {
|
||||
@ -78,7 +78,7 @@ public class JVMAddModulePackage {
|
||||
|
||||
// Null package argument, expect an NPE
|
||||
try {
|
||||
ModuleHelper.AddModulePackage(module1, null);
|
||||
ModuleHelper.AddModulePackage(module_one, null);
|
||||
throw new RuntimeException("Failed to get the expected NPE");
|
||||
} catch(NullPointerException e) {
|
||||
// Expected
|
||||
@ -86,7 +86,7 @@ public class JVMAddModulePackage {
|
||||
|
||||
// Existing package, expect an ISE
|
||||
try {
|
||||
ModuleHelper.AddModulePackage(module1, "yourpackage");
|
||||
ModuleHelper.AddModulePackage(module_one, "yourpackage");
|
||||
throw new RuntimeException("Failed to get the expected ISE");
|
||||
} catch(IllegalStateException e) {
|
||||
// Expected
|
||||
@ -94,7 +94,7 @@ public class JVMAddModulePackage {
|
||||
|
||||
// Invalid package name, expect an IAE
|
||||
try {
|
||||
ModuleHelper.AddModulePackage(module1, "your.package");
|
||||
ModuleHelper.AddModulePackage(module_one, "your.package");
|
||||
throw new RuntimeException("Failed to get the expected IAE");
|
||||
} catch(IllegalArgumentException e) {
|
||||
// Expected
|
||||
@ -102,7 +102,7 @@ public class JVMAddModulePackage {
|
||||
|
||||
// Invalid package name, expect an IAE
|
||||
try {
|
||||
ModuleHelper.AddModulePackage(module1, ";your/package");
|
||||
ModuleHelper.AddModulePackage(module_one, ";your/package");
|
||||
throw new RuntimeException("Failed to get the expected IAE");
|
||||
} catch(IllegalArgumentException e) {
|
||||
// Expected
|
||||
@ -110,7 +110,7 @@ public class JVMAddModulePackage {
|
||||
|
||||
// Invalid package name, expect an IAE
|
||||
try {
|
||||
ModuleHelper.AddModulePackage(module1, "7[743");
|
||||
ModuleHelper.AddModulePackage(module_one, "7[743");
|
||||
throw new RuntimeException("Failed to get the expected IAE");
|
||||
} catch(IllegalArgumentException e) {
|
||||
// Expected
|
||||
@ -118,7 +118,7 @@ public class JVMAddModulePackage {
|
||||
|
||||
// Empty package name, expect an IAE
|
||||
try {
|
||||
ModuleHelper.AddModulePackage(module1, "");
|
||||
ModuleHelper.AddModulePackage(module_one, "");
|
||||
throw new RuntimeException("Failed to get the expected IAE");
|
||||
} catch(IllegalArgumentException e) {
|
||||
// Expected
|
||||
@ -126,8 +126,8 @@ public class JVMAddModulePackage {
|
||||
|
||||
// Add package named "java" to an module defined to a class loader other than the boot or platform loader.
|
||||
try {
|
||||
// module1 is defined to a MyClassLoader class loader.
|
||||
ModuleHelper.AddModulePackage(module1, "java/foo");
|
||||
// module_one is defined to a MyClassLoader class loader.
|
||||
ModuleHelper.AddModulePackage(module_one, "java/foo");
|
||||
throw new RuntimeException("Failed to get the expected IAE");
|
||||
} catch(IllegalArgumentException e) {
|
||||
if (!e.getMessage().contains("prohibited package name")) {
|
||||
@ -136,10 +136,10 @@ public class JVMAddModulePackage {
|
||||
}
|
||||
|
||||
// Package "javabar" should be ok
|
||||
ModuleHelper.AddModulePackage(module1, "javabar");
|
||||
ModuleHelper.AddModulePackage(module_one, "javabar");
|
||||
|
||||
// Package named "java" defined to the boot class loader, should be ok
|
||||
Object module_javabase = module1.getClass().getModule();
|
||||
Object module_javabase = module_one.getClass().getModule();
|
||||
ModuleHelper.AddModulePackage(module_javabase, "java/foo");
|
||||
|
||||
// Package named "java" defined to the platform class loader, should be ok
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -49,7 +49,7 @@ public class JVMDefineModule {
|
||||
/* Invalid test, won't compile.
|
||||
// Invalid classloader argument, expect an IAE
|
||||
try {
|
||||
m = ModuleHelper.ModuleObject("mymodule1", new Object(), new String[] { "mypackage1" });
|
||||
m = ModuleHelper.ModuleObject("mymodule_one", new Object(), new String[] { "mypackage1" });
|
||||
ModuleHelper.DefineModule(m, "9.0", "mymodule/here", new String[] { "mypackage1" });
|
||||
throw new RuntimeException("Failed to get expected IAE for bad loader");
|
||||
} catch(IllegalArgumentException e) {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -79,10 +79,10 @@ public class JVMGetModuleByPkgName {
|
||||
}
|
||||
|
||||
MyClassLoader cl1 = new MyClassLoader();
|
||||
Module module1 = (Module)ModuleHelper.ModuleObject("module1", cl1, new String[] { "mypackage" });
|
||||
assertNotNull(module1, "Module should not be null");
|
||||
ModuleHelper.DefineModule(module1, "9.0", "module1/here", new String[] { "mypackage" });
|
||||
if (ModuleHelper.GetModuleByPackageName(cl1, "mypackage") != module1) {
|
||||
Module module_one = (Module)ModuleHelper.ModuleObject("module_one", cl1, new String[] { "mypackage" });
|
||||
assertNotNull(module_one, "Module should not be null");
|
||||
ModuleHelper.DefineModule(module_one, "9.0", "module_one/here", new String[] { "mypackage" });
|
||||
if (ModuleHelper.GetModuleByPackageName(cl1, "mypackage") != module_one) {
|
||||
throw new RuntimeException("Wrong module returned for cl1 mypackage");
|
||||
}
|
||||
}
|
||||
|
||||
@ -84,7 +84,7 @@ public class ModuleHelper {
|
||||
}
|
||||
|
||||
ModuleDescriptor descriptor =
|
||||
ModuleDescriptor.module(name).contains(pkg_set).build();
|
||||
ModuleDescriptor.newModule(name).packages(pkg_set).build();
|
||||
URI uri = URI.create("module:/" + name);
|
||||
|
||||
return java.lang.reflect.ModuleHelper.newModule(loader, descriptor);
|
||||
|
||||
@ -43,7 +43,7 @@ public class ModuleOptionsTest {
|
||||
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
|
||||
"--add-modules=i_dont_exist", "--add-modules=java.base", "-version");
|
||||
OutputAnalyzer output = new OutputAnalyzer(pb.start());
|
||||
output.shouldContain("ResolutionException");
|
||||
output.shouldContain("FindException");
|
||||
output.shouldContain("i_dont_exist");
|
||||
output.shouldHaveExitValue(1);
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -22,7 +22,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* A custom system ClassLoader to define the module "m2" to during iterations of
|
||||
* A custom system ClassLoader to define the module "m2x" to during iterations of
|
||||
* differing test runs within the test ModuleStress.java
|
||||
*/
|
||||
public class CustomSystemClassLoader extends ClassLoader {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -35,15 +35,15 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
//
|
||||
// ClassLoader1 --> defines m1 --> packages p1
|
||||
// ClassLoader2 --> defines m2 --> packages p2
|
||||
// Java System Class Loader --> defines m3 --> packages p3
|
||||
// ClassLoader1 --> defines m1x --> packages p1
|
||||
// ClassLoader2 --> defines m2x --> packages p2
|
||||
// Java System Class Loader --> defines m3x --> packages p3
|
||||
//
|
||||
// m1 can read m2
|
||||
// package p2 in m2 is exported to m1 and m3
|
||||
// m1x can read m2x
|
||||
// package p2 in m2x is exported to m1x and m3x
|
||||
//
|
||||
// class p1.c1 defined in m1 tries to access p2.c2 defined in m2
|
||||
// Access allowed since m1 can read m2 and package p2 is exported to m1.
|
||||
// class p1.c1 defined in m1x tries to access p2.c2 defined in m2x
|
||||
// Access allowed since m1x can read m2x and package p2 is exported to m1x.
|
||||
//
|
||||
public class ModuleNonBuiltinCLMain {
|
||||
|
||||
@ -52,62 +52,62 @@ public class ModuleNonBuiltinCLMain {
|
||||
// publically defined classes within packages of those modules.
|
||||
public void createLayerOnBoot() throws Throwable {
|
||||
|
||||
// Define module: m1
|
||||
// Can read: java.base, m2
|
||||
// Define module: m1x
|
||||
// Can read: java.base, m2x
|
||||
// Packages: p1
|
||||
// Packages exported: p1 is exported to unqualifiedly
|
||||
ModuleDescriptor descriptor_m1 =
|
||||
ModuleDescriptor.module("m1")
|
||||
ModuleDescriptor descriptor_m1x =
|
||||
ModuleDescriptor.newModule("m1x")
|
||||
.requires("java.base")
|
||||
.requires("m2")
|
||||
.requires("m2x")
|
||||
.exports("p1")
|
||||
.build();
|
||||
|
||||
// Define module: m2
|
||||
// Can read: java.base, m3
|
||||
// Define module: m2x
|
||||
// Can read: java.base, m3x
|
||||
// Packages: p2
|
||||
// Packages exported: package p2 is exported to m1 and m3
|
||||
// Packages exported: package p2 is exported to m1x and m3x
|
||||
Set<String> targets = new HashSet<>();
|
||||
targets.add("m1");
|
||||
targets.add("m3");
|
||||
ModuleDescriptor descriptor_m2 =
|
||||
ModuleDescriptor.module("m2")
|
||||
targets.add("m1x");
|
||||
targets.add("m3x");
|
||||
ModuleDescriptor descriptor_m2x =
|
||||
ModuleDescriptor.newModule("m2x")
|
||||
.requires("java.base")
|
||||
.requires("m3")
|
||||
.requires("m3x")
|
||||
.exports("p2", targets)
|
||||
.build();
|
||||
|
||||
// Define module: m3
|
||||
// Define module: m3x
|
||||
// Can read: java.base
|
||||
// Packages: p3
|
||||
// Packages exported: none
|
||||
ModuleDescriptor descriptor_m3 =
|
||||
ModuleDescriptor.module("m3")
|
||||
ModuleDescriptor descriptor_m3x =
|
||||
ModuleDescriptor.newModule("m3x")
|
||||
.requires("java.base")
|
||||
.build();
|
||||
|
||||
// Set up a ModuleFinder containing all modules for this layer.
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1, descriptor_m2, descriptor_m3);
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1x, descriptor_m2x, descriptor_m3x);
|
||||
|
||||
// Resolves "m1"
|
||||
// Resolves "m1x"
|
||||
Configuration cf = Layer.boot()
|
||||
.configuration()
|
||||
.resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
|
||||
.resolve(finder, ModuleFinder.of(), Set.of("m1x"));
|
||||
|
||||
// map each module to differing user defined class loaders for this test
|
||||
Map<String, ClassLoader> map = new HashMap<>();
|
||||
Loader1 cl1 = new Loader1();
|
||||
Loader2 cl2 = new Loader2();
|
||||
ClassLoader cl3 = ClassLoader.getSystemClassLoader();
|
||||
map.put("m1", cl1);
|
||||
map.put("m2", cl2);
|
||||
map.put("m3", cl3);
|
||||
map.put("m1x", cl1);
|
||||
map.put("m2x", cl2);
|
||||
map.put("m3x", cl3);
|
||||
|
||||
// Create Layer that contains m1 & m2
|
||||
// Create Layer that contains m1x & m2x
|
||||
Layer layer = Layer.boot().defineModules(cf, map::get);
|
||||
assertTrue(layer.findLoader("m1") == cl1);
|
||||
assertTrue(layer.findLoader("m2") == cl2);
|
||||
assertTrue(layer.findLoader("m3") == cl3);
|
||||
assertTrue(layer.findLoader("m1x") == cl1);
|
||||
assertTrue(layer.findLoader("m2x") == cl2);
|
||||
assertTrue(layer.findLoader("m3x") == cl3);
|
||||
assertTrue(layer.findLoader("java.base") == null);
|
||||
|
||||
// now use the same loader to load class p1.c1
|
||||
@ -115,7 +115,7 @@ public class ModuleNonBuiltinCLMain {
|
||||
try {
|
||||
p1_c1_class.newInstance();
|
||||
} catch (IllegalAccessError e) {
|
||||
throw new RuntimeException("Test Failed, an IAE should not be thrown since p2 is exported qualifiedly to m1");
|
||||
throw new RuntimeException("Test Failed, an IAE should not be thrown since p2 is exported qualifiedly to m1x");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -34,14 +34,14 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
//
|
||||
// ClassLoader1 --> defines m1 --> packages p1
|
||||
// ClassLoader1 --> defines m2 --> packages p2
|
||||
// ClassLoader1 --> defines m1x --> packages p1
|
||||
// ClassLoader1 --> defines m2x --> packages p2
|
||||
//
|
||||
// m1 can read m2
|
||||
// package p2 in m2 is exported to m1
|
||||
// m1x can read m2x
|
||||
// package p2 in m2x is exported to m1x
|
||||
//
|
||||
// class p1.c1 defined in m1 tries to access p2.c2 defined in m2
|
||||
// Access allowed since m1 can read m2 and package p2 is exported to m1.
|
||||
// class p1.c1 defined in m1x tries to access p2.c2 defined in m2x
|
||||
// Access allowed since m1x can read m2x and package p2 is exported to m1x.
|
||||
//
|
||||
public class ModuleSameCLMain {
|
||||
|
||||
@ -50,45 +50,45 @@ public class ModuleSameCLMain {
|
||||
// publically defined classes within packages of those modules.
|
||||
public void createLayerOnBoot() throws Throwable {
|
||||
|
||||
// Define module: m1
|
||||
// Can read: java.base, m2
|
||||
// Define module: m1x
|
||||
// Can read: java.base, m2x
|
||||
// Packages: p1
|
||||
// Packages exported: p1 is exported to unqualifiedly
|
||||
ModuleDescriptor descriptor_m1 =
|
||||
ModuleDescriptor.module("m1")
|
||||
ModuleDescriptor descriptor_m1x =
|
||||
ModuleDescriptor.newModule("m1x")
|
||||
.requires("java.base")
|
||||
.requires("m2")
|
||||
.requires("m2x")
|
||||
.exports("p1")
|
||||
.build();
|
||||
|
||||
// Define module: m2
|
||||
// Define module: m2x
|
||||
// Can read: java.base
|
||||
// Packages: p2
|
||||
// Packages exported: package p2 is exported to m1
|
||||
ModuleDescriptor descriptor_m2 =
|
||||
ModuleDescriptor.module("m2")
|
||||
// Packages exported: package p2 is exported to m1x
|
||||
ModuleDescriptor descriptor_m2x =
|
||||
ModuleDescriptor.newModule("m2x")
|
||||
.requires("java.base")
|
||||
.exports("p2", Set.of("m1"))
|
||||
.exports("p2", Set.of("m1x"))
|
||||
.build();
|
||||
|
||||
// Set up a ModuleFinder containing all modules for this layer.
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1, descriptor_m2);
|
||||
ModuleFinder finder = ModuleLibrary.of(descriptor_m1x, descriptor_m2x);
|
||||
|
||||
// Resolves "m1"
|
||||
// Resolves "m1x"
|
||||
Configuration cf = Layer.boot()
|
||||
.configuration()
|
||||
.resolveRequires(finder, ModuleFinder.of(), Set.of("m1"));
|
||||
.resolve(finder, ModuleFinder.of(), Set.of("m1x"));
|
||||
|
||||
// map each module to the same class loader for this test
|
||||
Map<String, ClassLoader> map = new HashMap<>();
|
||||
Loader1 cl1 = new Loader1();
|
||||
map.put("m1", cl1);
|
||||
map.put("m2", cl1);
|
||||
map.put("m1x", cl1);
|
||||
map.put("m2x", cl1);
|
||||
|
||||
// Create Layer that contains m1 & m2
|
||||
// Create Layer that contains m1x & m2x
|
||||
Layer layer = Layer.boot().defineModules(cf, map::get);
|
||||
assertTrue(layer.findLoader("m1") == cl1);
|
||||
assertTrue(layer.findLoader("m2") == cl1);
|
||||
assertTrue(layer.findLoader("m1x") == cl1);
|
||||
assertTrue(layer.findLoader("m2x") == cl1);
|
||||
assertTrue(layer.findLoader("java.base") == null);
|
||||
|
||||
// now use the same loader to load class p1.c1
|
||||
@ -96,7 +96,7 @@ public class ModuleSameCLMain {
|
||||
try {
|
||||
p1_c1_class.newInstance();
|
||||
} catch (IllegalAccessError e) {
|
||||
throw new RuntimeException("Test Failed, an IAE should not be thrown since p2 is exported qualifiedly to m1");
|
||||
throw new RuntimeException("Test Failed, an IAE should not be thrown since p2 is exported qualifiedly to m1x");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -83,7 +83,7 @@ public class ModuleStress {
|
||||
InMemoryJavaCompiler.compile("p1.c1", source1), System.getProperty("test.classes"));
|
||||
|
||||
// Test #2: Load two modules defined to the same customer class loader.
|
||||
// m1's module readability list and package p2's exportability should
|
||||
// m1x's module readability list and package p2's exportability should
|
||||
// not be walked at a GC safepoint since both modules are defined to
|
||||
// the same loader and thus have the exact same life cycle.
|
||||
pb = ProcessTools.createJavaProcessBuilder(
|
||||
@ -97,7 +97,7 @@ public class ModuleStress {
|
||||
.shouldHaveExitValue(0);
|
||||
|
||||
// Test #3: Load two modules in differing custom class loaders.
|
||||
// m1's module readability list and package p2's exportability list must
|
||||
// m1x's module readability list and package p2's exportability list must
|
||||
// be walked at a GC safepoint since both modules are defined to non-builtin
|
||||
// class loaders which could die and thus be unloaded.
|
||||
pb = ProcessTools.createJavaProcessBuilder(
|
||||
@ -106,15 +106,15 @@ public class ModuleStress {
|
||||
"ModuleNonBuiltinCLMain");
|
||||
|
||||
oa = new OutputAnalyzer(pb.start());
|
||||
oa.shouldContain("module m1 reads list must be walked")
|
||||
.shouldContain("package p2 defined in module m2, exports list must be walked")
|
||||
.shouldNotContain("module m2 reads list must be walked")
|
||||
oa.shouldContain("module m1x reads list must be walked")
|
||||
.shouldContain("package p2 defined in module m2x, exports list must be walked")
|
||||
.shouldNotContain("module m2x reads list must be walked")
|
||||
.shouldHaveExitValue(0);
|
||||
|
||||
// Test #4: Load two modules in differing custom class loaders,
|
||||
// of which one has been designated as the custom system class loader
|
||||
// via -Djava.system.class.loader=CustomSystemClassLoader. Since
|
||||
// m3 is defined to the system class loader, m2's module readability
|
||||
// m3x is defined to the system class loader, m2x's module readability
|
||||
// list does not have to be walked at a GC safepoint, but package p2's
|
||||
// exportability list does.
|
||||
pb = ProcessTools.createJavaProcessBuilder(
|
||||
@ -124,8 +124,8 @@ public class ModuleStress {
|
||||
"ModuleNonBuiltinCLMain");
|
||||
|
||||
oa = new OutputAnalyzer(pb.start());
|
||||
oa.shouldContain("package p2 defined in module m2, exports list must be walked")
|
||||
.shouldNotContain("module m2 reads list must be walked")
|
||||
oa.shouldContain("package p2 defined in module m2x, exports list must be walked")
|
||||
.shouldNotContain("module m2x reads list must be walked")
|
||||
.shouldHaveExitValue(0);
|
||||
|
||||
}
|
||||
|
||||
@ -48,7 +48,7 @@ public class Main {
|
||||
|
||||
Configuration cf = layerBoot
|
||||
.configuration()
|
||||
.resolveRequires(ModuleFinder.of(), finder, Set.of(MODULE_NAME));
|
||||
.resolve(ModuleFinder.of(), finder, Set.of(MODULE_NAME));
|
||||
|
||||
Module testModule = Main.class.getModule();
|
||||
ClassLoader scl = ClassLoader.getSystemClassLoader();
|
||||
|
||||
@ -48,7 +48,7 @@ public class MainGC {
|
||||
|
||||
Configuration cf = layerBoot
|
||||
.configuration()
|
||||
.resolveRequires(ModuleFinder.of(), finder, Set.of(MODULE_NAME));
|
||||
.resolve(ModuleFinder.of(), finder, Set.of(MODULE_NAME));
|
||||
|
||||
Module testModule = MainGC.class.getModule();
|
||||
ClassLoader scl = ClassLoader.getSystemClassLoader();
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -38,8 +38,8 @@ public class PatchModuleDupModule {
|
||||
|
||||
public static void main(String args[]) throws Exception {
|
||||
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
|
||||
"--patch-module=module1=module1_dir",
|
||||
"--patch-module=module1=module1_dir",
|
||||
"--patch-module=module_one=module_one_dir",
|
||||
"--patch-module=module_one=module_one_dir",
|
||||
"-version");
|
||||
OutputAnalyzer output = new OutputAnalyzer(pb.start());
|
||||
output.shouldContain("java.lang.ExceptionInInitializerError");
|
||||
|
||||
@ -82,12 +82,11 @@ public class JvmtiGetAllModulesTest {
|
||||
Asserts.assertEquals(Layer.boot().modules(), getModulesJVMTI());
|
||||
|
||||
// Load a new named module
|
||||
ModuleDescriptor descriptor
|
||||
= ModuleDescriptor.module(MY_MODULE_NAME).build();
|
||||
ModuleDescriptor descriptor = ModuleDescriptor.newModule(MY_MODULE_NAME).build();
|
||||
ModuleFinder finder = finderOf(descriptor);
|
||||
ClassLoader loader = new ClassLoader() {};
|
||||
Configuration parent = Layer.boot().configuration();
|
||||
Configuration cf = parent.resolveRequires(finder, ModuleFinder.of(), Set.of(MY_MODULE_NAME));
|
||||
Configuration cf = parent.resolve(finder, ModuleFinder.of(), Set.of(MY_MODULE_NAME));
|
||||
Layer my = Layer.boot().defineModules(cf, m -> loader);
|
||||
|
||||
// Verify that the loaded module is indeed reported by JVMTI
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user