changeset 14803:387f9070f3bf

Layer.createWithXXX need additional permisions specified Misc. clean-up
author alanb
date Fri, 18 Dec 2015 12:11:06 +0000
parents ec4fb763dbce
children bfe6c859bc80
files src/java.base/share/classes/java/lang/reflect/Layer.java src/java.base/share/classes/jdk/internal/misc/Loader.java
diffstat 2 files changed, 19 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/java/lang/reflect/Layer.java	Thu Dec 17 12:10:05 2015 -0800
+++ b/src/java.base/share/classes/java/lang/reflect/Layer.java	Fri Dec 18 12:11:06 2015 +0000
@@ -72,6 +72,7 @@
  * need to follow the convention in this package.
  *
  * @since 9
+ * @see Module#getLayer()
  */
 
 public final class Layer {
@@ -237,7 +238,8 @@
      *         If the parent of the given configuration is not the configuration
      *         of the parent {@code Layer}
      * @throws SecurityException
-     *         If {@code RuntimePermission("createClassLoader")} is denied by
+     *         If {@code RuntimePermission("createClassLoader")} or
+     *         {@code RuntimePermission("getClassLoader")} is denied by
      *         the security manager
      *
      * @see #findLoader
@@ -294,7 +296,8 @@
      *         If all modules cannot be defined to the same class loader for any
      *         of the reasons listed above
      * @throws SecurityException
-     *         If {@code RuntimePermission("createClassLoader")} is denied by
+     *         If {@code RuntimePermission("createClassLoader")} or
+     *         {@code RuntimePermission("getClassLoader")} is denied by
      *         the security manager
      *
      * @see #findLoader
--- a/src/java.base/share/classes/jdk/internal/misc/Loader.java	Thu Dec 17 12:10:05 2015 -0800
+++ b/src/java.base/share/classes/jdk/internal/misc/Loader.java	Fri Dec 18 12:11:06 2015 +0000
@@ -243,7 +243,18 @@
                 String target = mref.descriptor().name();
                 for (ModuleDescriptor.Exports e : rd.descriptor().exports()) {
                     Optional<Set<String>> targets = e.targets();
-                    if (!targets.isPresent() || targets.get().contains(target)) {
+
+                    boolean delegate;
+                    if (targets.isPresent()) {
+                        // qualified export in same configuration
+                        delegate = (rd.configuration() == cf)
+                                && targets.get().contains(target);
+                    } else {
+                        // unqualified
+                        delegate = true;
+                    }
+
+                    if (delegate) {
                         String pn = e.source();
                         ClassLoader l = remotePackageToLoader.putIfAbsent(pn, loader);
                         if (l != null && l != loader) {
@@ -424,7 +435,8 @@
                 // define the package if not already defined
                 String pn = packageName(cn);
                 if (getDefinedPackage(pn) == null) {
-                    definePackage(pn, loadedModule);
+                    URL url = loadedModule.location();
+                    definePackage(pn, null, null, null, null, null, null, url);
                 }
 
                 return defineClass(cn, bb, loadedModule.codeSource());
@@ -440,20 +452,6 @@
     }
 
 
-    // -- packages
-
-    /**
-     * Define a Package this to this class loader. The resulting Package
-     * is sealed with the code source that is the module location.
-     */
-    private Package definePackage(String pn, LoadedModule loadedModule) {
-        URL url = loadedModule.location();
-
-        // can this throw IAE?
-        return definePackage(pn, null, null, null, null, null, null, url);
-    }
-
-
     // -- permissions
 
     /**