< prev index next >

src/java.base/share/classes/java/lang/Module.java

Print this page

        

@@ -124,11 +124,11 @@
         this.loader = loader;
         this.descriptor = descriptor;
 
         // define module to VM
 
-        boolean isOpen = descriptor.isOpen();
+        boolean isOpen = descriptor.isOpen() || descriptor.isAutomatic();
         Version version = descriptor.version().orElse(null);
         String vs = Objects.toString(version, null);
         String loc = Objects.toString(uri, null);
         String[] packages = descriptor.packages().toArray(new String[0]);
         defineModule0(this, isOpen, vs, loc, packages);

@@ -1040,13 +1040,10 @@
         // update VM first in case it fails. This is a no-op if another thread
         // beats us to add the package first
         if (syncVM) {
             // throws IllegalStateException if defined to another module
             addPackage0(this, pn);
-            if (descriptor.isOpen() || descriptor.isAutomatic()) {
-                addExportsToAll0(this, pn);
-            }
         }
         extraPackages.putIfAbsent(pn, Boolean.TRUE);
     }
 
 

@@ -1143,13 +1140,16 @@
             // automatic modules read all unnamed modules
             if (descriptor.isAutomatic()) {
                 m.implAddReads(ALL_UNNAMED_MODULE, true);
             }
 
-            // exports and opens
+            // export and open packages, skipped for open and automatic
+            // modules since they are treated as if all packages are open
+            if (!descriptor.isOpen() && !descriptor.isAutomatic()) { 
             initExportsAndOpens(m, nameToSource, nameToModule, layer.parents());
         }
+        }
 
         // register the modules in the boot layer
         if (isBootLayer) {
             for (ResolvedModule resolvedModule : cf.modules()) {
                 ModuleReference mref = resolvedModule.reference();

@@ -1205,25 +1205,15 @@
      */
     private static void initExportsAndOpens(Module m,
                                             Map<String, Module> nameToSource,
                                             Map<String, Module> nameToModule,
                                             List<ModuleLayer> parents) {
-        // The VM doesn't special case open or automatic modules so need to
-        // export all packages
-        ModuleDescriptor descriptor = m.getDescriptor();
-        if (descriptor.isOpen() || descriptor.isAutomatic()) {
-            assert descriptor.opens().isEmpty();
-            for (String source : descriptor.packages()) {
-                addExportsToAll0(m, source);
-            }
-            return;
-        }
-
         Map<String, Set<Module>> openPackages = new HashMap<>();
         Map<String, Set<Module>> exportedPackages = new HashMap<>();
 
         // process the open packages first
+        ModuleDescriptor descriptor = m.getDescriptor();
         for (Opens opens : descriptor.opens()) {
             String source = opens.source();
 
             if (opens.isQualified()) {
                 // qualified opens
< prev index next >