Layer Primitives (1/3): addExports()

David M. Lloyd david.lloyd at redhat.com
Wed May 10 20:31:46 UTC 2017


I apologize, the patch given corresponds to an older version.  The 
updated patch is as follows:

diff --git a/jdk/src/java.base/share/classes/java/lang/ModuleLayer.java 
b/jdk/src/java.base/share/classes/java/lang/ModuleLayer.java
index 549662f..58ffbd2 100644
--- a/jdk/src/java.base/share/classes/java/lang/ModuleLayer.java
+++ b/jdk/src/java.base/share/classes/java/lang/ModuleLayer.java
@@ -48,6 +48,7 @@ import jdk.internal.loader.ClassLoaderValue;
  import jdk.internal.loader.Loader;
  import jdk.internal.loader.LoaderPool;
  import jdk.internal.module.ServicesCatalog;
+import jdk.internal.reflect.Reflection;
  import sun.security.util.SecurityConstants;


@@ -269,6 +270,39 @@ public final class ModuleLayer {
              source.implAddOpens(pn, target);
              return this;
          }
+
+        /**
+         * Updates module {@code source} in the layer to export a 
package to
+         * module {@code target}. This method is a no-op if {@code source}
+         * already exports the package to at least {@code target}.
+         *
+         * @param  source
+         *         The source module
+         * @param  pn
+         *         The package name
+         * @param  other
+         *         The module to export to
+         *
+         * @return This controller
+         *
+         * @throws IllegalArgumentException
+         *         If {@code pn} is {@code null}, or {@code source} is 
not in the layer
+         *         or the package is not in the source module
+         *
+         * @see Module#addExports
+         */
+        public Controller addExports(Module source, String pn, Module 
other) {
+            if (pn == null)
+                throw new IllegalArgumentException("package is null");
+            Objects.requireNonNull(other);
+
+            if (source.isNamed()) {
+                ensureInLayer(source);
+                source.implAddExports(pn, other);
+            }
+
+            return this;
+        }
      }





On 05/10/2017 03:09 PM, David M. Lloyd wrote:
> I'm now breaking up each layer primitive in order to try to get some 
> kind of focused/non-blanket bidirectional discussion on each one, with a 
> view towards forward progress.  I'm targeting what I view as a 
> minimum/compromise set.
> 
> I'd like to re-propose adding the following method to the layer 
> controller specification and implementation [1].
> 
> Justification:
> 
> • No new functionality is introduced to the specification or 
> implementation by this method, other than to simplify access for layer 
> controllers.
> • Module#addExports() exists and does the exact same thing.
> • It is not reasonable to require containers to generate bytecode within 
> their contained modules in order to call this method.
> • Since Module#addExports() exists, there is no scenario in which adding 
> this primitive to the layer controller could possibly cause any form of 
> liability or technical debt that does not already exist.
> • ModuleLayer.Controller#addOpens() exists, which grants even wider 
> access than addExports() would, thus there is no security risk that does 
> not already exist in a greater form.
> • The controller is only available to user-defined Layers, so there is 
> no risk to the platform, jlink, etc.
> • The patch itself is very small and simple, and should be very low-risk.
> 
> Drawbacks:
> 
> None that I am aware of.
> 
> Patch information:
> 
> The content and format of the JavaDoc are drawn from neighboring 
> methods.  I relinquish any copyright claim to the patch in this mail. 
> Please do not get bogged down by any formatting problems introduced by 
> the mailing list; the purpose of directly including the patch is to give 
> a clear, unambiguous subject for discussion.  I can provide a proper 
> webrev (or whatever other form is requested) if needed.
> 
> [1]:
> 
> diff --git a/jdk/src/java.base/share/classes/java/lang/ModuleLayer.java 
> b/jdk/src/java.base/share/classes/java/lang/ModuleLayer.java
> index 549662f..20e3021 100644
> --- a/jdk/src/java.base/share/classes/java/lang/ModuleLayer.java
> +++ b/jdk/src/java.base/share/classes/java/lang/ModuleLayer.java
> @@ -269,6 +269,34 @@ public final class ModuleLayer {
>               source.implAddOpens(pn, target);
>               return this;
>           }
> +
> +        /**
> +         * Updates module {@code source} in the layer to export a 
> package to
> +         * module {@code target}. This method is a no-op if {@code source}
> +         * already exports the package to at least {@code target}.
> +         *
> +         * @param  source
> +         *         The source module
> +         * @param  pn
> +         *         The package name
> +         * @param  target
> +         *         The target module to read
> +         *
> +         * @return This controller
> +         *
> +         * @throws IllegalArgumentException
> +         *         If {@code source} is not in the layer or the package 
> is not
> +         *         in the source module
> +         *
> +         * @see Module#addExports
> +         */
> +        public Controller addExports(Module source, String pn, Module 
> target) {
> +            Objects.requireNonNull(source);
> +            Objects.requireNonNull(target);
> +            ensureInLayer(source);
> +            source.implAddExports(pn, target);
> +            return this;
> +        }
>       }
> 
> 
> 


-- 
- DML


More information about the jpms-spec-experts mailing list