changeset 19509:081f60103878

Add usage note to addOpens Random clean-up
author alanb
date Thu, 13 Apr 2017 18:36:27 +0100
parents 6aa95347da12
children 09476fe742fe
files src/java.base/share/classes/java/lang/Module.java src/java.base/share/classes/jdk/internal/module/ModuleHashesBuilder.java src/java.base/share/classes/jdk/internal/module/ModuleInfo.java src/java.base/share/classes/jdk/internal/module/ModulePath.java src/java.base/share/classes/jdk/internal/module/ModuleResolution.java src/java.base/share/classes/sun/launcher/LauncherHelper.java
diffstat 6 files changed, 45 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/java/lang/Module.java	Thu Apr 13 17:31:25 2017 +0100
+++ b/src/java.base/share/classes/java/lang/Module.java	Thu Apr 13 18:36:27 2017 +0100
@@ -215,8 +215,8 @@
     }
 
     /**
-     * Returns the layer that contains this module or {@code null} if this
-     * module is not in a layer.
+     * Returns the module layer that contains this module or {@code null} if
+     * this module is not in a module layer.
      *
      * A module layer contains named modules and therefore this method always
      * returns {@code null} when invoked on an unnamed module.
@@ -691,6 +691,13 @@
      * <p> This method has no effect if the package is already <em>open</em>
      * to the given module. </p>
      *
+     * @apiNote This method can be used for cases where a <em>consumer
+     * module</em> uses a qualified opens to open a package to an <em>API
+     * module</em> but where the reflective access to the members of classes in
+     * the consumer module is delegated to code in another module. Code in the
+     * API module can use this method to open the package in the consumer module
+     * to the other module.
+     *
      * @param  pn
      *         The package name
      * @param  other
@@ -1458,11 +1465,11 @@
      *     encapsulated. </li>
      *
      *     <li> A <em>package name</em> is derived from the resource name. If
-     *     the package name is a {@link #getPackages() package} in the module
-     *     then the resource can only be located by the caller of this method
-     *     when the package is {@link #isOpen(String,Module) open} to at least
-     *     the caller's module. If the resource is not in a package in the module
-     *     then the resource is not encapsulated. </li>
+     *     the package name is a {@linkplain #getPackages() package} in the
+     *     module then the resource can only be located by the caller of this
+     *     method when the package is {@linkplain #isOpen(String,Module) open}
+     *     to at least the the caller's module. If the resource is not in a
+     *     package in the module then the resource is not encapsulated. </li>
      * </ul>
      *
      * <p> In the above, the <em>package name</em> for a resource is derived
--- a/src/java.base/share/classes/jdk/internal/module/ModuleHashesBuilder.java	Thu Apr 13 17:31:25 2017 +0100
+++ b/src/java.base/share/classes/jdk/internal/module/ModuleHashesBuilder.java	Thu Apr 13 18:36:27 2017 +0100
@@ -138,7 +138,7 @@
     }
 
     /*
-     * Utilty class
+     * Utility class
      */
     static class Graph<T> {
         private final Set<T> nodes;
--- a/src/java.base/share/classes/jdk/internal/module/ModuleInfo.java	Thu Apr 13 17:31:25 2017 +0100
+++ b/src/java.base/share/classes/jdk/internal/module/ModuleInfo.java	Thu Apr 13 18:36:27 2017 +0100
@@ -560,7 +560,6 @@
         return new ModuleTarget(osName, osArch);
     }
 
-
     /**
      * Reads the ModuleHashes attribute
      */
@@ -612,7 +611,6 @@
         return new ModuleResolution(flags);
     }
 
-
     /**
      * Returns true if the given attribute can be present at most once
      * in the class file. Returns false otherwise.
--- a/src/java.base/share/classes/jdk/internal/module/ModulePath.java	Thu Apr 13 17:31:25 2017 +0100
+++ b/src/java.base/share/classes/jdk/internal/module/ModulePath.java	Thu Apr 13 18:36:27 2017 +0100
@@ -59,6 +59,7 @@
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import java.util.stream.Collectors;
+import java.util.zip.ZipException;
 import java.util.zip.ZipFile;
 
 import jdk.internal.jmod.JmodFile;
@@ -617,6 +618,8 @@
             }
 
             return ModuleReferences.newJarModule(attrs, patcher, file);
+        } catch (ZipException e) {
+            throw new FindException("Error reading " + file, e);
         }
     }
 
--- a/src/java.base/share/classes/jdk/internal/module/ModuleResolution.java	Thu Apr 13 17:31:25 2017 +0100
+++ b/src/java.base/share/classes/jdk/internal/module/ModuleResolution.java	Thu Apr 13 18:36:27 2017 +0100
@@ -39,6 +39,10 @@
         this.value = value;
     }
 
+    public int value() {
+        return value;
+    }
+
     public static ModuleResolution empty() {
         return new ModuleResolution(0);
     }
@@ -74,35 +78,30 @@
             throw new InternalError("cannot add deprecated for removal to " + value);
         return new ModuleResolution(value | WARN_DEPRECATED_FOR_REMOVAL);
     }
+
     public ModuleResolution withIncubating() {
         if ((value & (WARN_DEPRECATED | WARN_DEPRECATED_FOR_REMOVAL)) != 0)
             throw new InternalError("cannot add incubating to " + value);
         return new ModuleResolution(value | WARN_INCUBATING);
     }
 
-    public int value() {
-        return value;
-    }
-
     public static boolean doNotResolveByDefault(ModuleReference mref) {
         // get the DO_NOT_RESOLVE_BY_DEFAULT flag, if any
-        if (!(mref instanceof ModuleReferenceImpl))
-            return false;
-
-        ModuleResolution mres = ((ModuleReferenceImpl)mref).moduleResolution();
-        if (mres != null)
-            return mres.doNotResolveByDefault();
+        if (mref instanceof ModuleReferenceImpl) {
+            ModuleResolution mres = ((ModuleReferenceImpl) mref).moduleResolution();
+            if (mres != null)
+                return mres.doNotResolveByDefault();
+        }
 
         return false;
     }
 
     public static boolean hasIncubatingWarning(ModuleReference mref) {
-        if (!(mref instanceof ModuleReferenceImpl))
-            return false;
-
-        ModuleResolution mres = ((ModuleReferenceImpl)mref).moduleResolution();
-        if (mres != null)
-            return mres.hasIncubatingWarning();
+        if (mref instanceof ModuleReferenceImpl) {
+            ModuleResolution mres = ((ModuleReferenceImpl) mref).moduleResolution();
+            if (mres != null)
+                return mres.hasIncubatingWarning();
+        }
 
         return false;
     }
--- a/src/java.base/share/classes/sun/launcher/LauncherHelper.java	Thu Apr 13 17:31:25 2017 +0100
+++ b/src/java.base/share/classes/sun/launcher/LauncherHelper.java	Thu Apr 13 18:36:27 2017 +0100
@@ -977,14 +977,13 @@
         listModule(mref);
 
         // unqualified exports (sorted by package)
-        Set<Exports> exports = new TreeSet<>(Comparator.comparing(Exports::source));
-        md.exports().stream().filter(e -> !e.isQualified()).forEach(exports::add);
-        for (Exports e : exports) {
-            String sourceAndMods = Stream.concat(Stream.of(e.source()),
-                                                 toStringStream(e.modifiers()))
-                    .collect(Collectors.joining(" "));
-            ostream.format("exports %s%n", sourceAndMods);
-        }
+        md.exports().stream()
+            .filter(e -> !e.isQualified())
+            .sorted(Comparator.comparing(Exports::source))
+            .map(e -> Stream.concat(Stream.of(e.source()),
+                                    toStringStream(e.modifiers()))
+                    .collect(Collectors.joining(" ")))
+            .forEach(sourceAndMods -> ostream.format("exports %s%n", sourceAndMods));
 
         // dependences
         for (Requires r : md.requires()) {
@@ -993,9 +992,9 @@
                     .collect(Collectors.joining(" "));
             ostream.format("requires %s", nameAndMods);
             finder.find(r.name())
-                    .map(ModuleReference::descriptor)
-                    .filter(ModuleDescriptor::isAutomatic)
-                    .ifPresent(any -> ostream.print(" automatic"));
+                .map(ModuleReference::descriptor)
+                .filter(ModuleDescriptor::isAutomatic)
+                .ifPresent(any -> ostream.print(" automatic"));
             ostream.println();
         }
 
@@ -1046,8 +1045,8 @@
         ModuleDescriptor md = mref.descriptor();
         ostream.print(md.toNameAndVersion());
         mref.location()
-            .filter(uri -> !isJrt(uri))
-            .ifPresent(uri -> ostream.format(" %s", uri));
+                .filter(uri -> !isJrt(uri))
+                .ifPresent(uri -> ostream.format(" %s", uri));
         if (md.isOpen())
             ostream.print(" open");
         if (md.isAutomatic())