Layer Primitives (1/3): addExports()

David M. Lloyd david.lloyd at
Wed May 10 20:09:20 UTC 2017

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].


• No new functionality is introduced to the specification or 
implementation by this method, other than to simplify access for layer 
• 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.


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.


diff --git a/jdk/src/java.base/share/classes/java/lang/ 
index 549662f..20e3021 100644
--- a/jdk/src/java.base/share/classes/java/lang/
+++ b/jdk/src/java.base/share/classes/java/lang/
@@ -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;
+        }


More information about the jpms-spec-observers mailing list