# HG changeset patch # User martin # Date 1518139557 28800 # Thu Feb 08 17:25:57 2018 -0800 # Node ID e32443b07c6ddd2d17b652be82a2f4af8448f558 # Parent 99505f1c6b55f48f5cd724965d445415e387baa6 8198481: Coding style cleanups for src/java.base/share/classes/jdk/internal/loader/ClassLoaders.java Reviewed-by: mchung, alanb diff --git a/src/java.base/share/classes/jdk/internal/loader/BootLoader.java b/src/java.base/share/classes/jdk/internal/loader/BootLoader.java --- a/src/java.base/share/classes/jdk/internal/loader/BootLoader.java +++ b/src/java.base/share/classes/jdk/internal/loader/BootLoader.java @@ -51,12 +51,12 @@ * Find resources and packages in modules defined to the boot class loader or * resources and packages on the "boot class path" specified via -Xbootclasspath/a. */ - public class BootLoader { private BootLoader() { } - // The unnamed module for the boot loader + /** The unnamed module for the boot loader */ private static final Module UNNAMED_MODULE; + private static final String JAVA_HOME = System.getProperty("java.home"); static { @@ -64,10 +64,10 @@ setBootLoaderUnnamedModule0(UNNAMED_MODULE); } - // ServiceCatalog for the boot class loader + /** ServiceCatalog for the boot class loader */ private static final ServicesCatalog SERVICES_CATALOG = ServicesCatalog.create(); - // ClassLoaderValue map for boot class loader + /** ClassLoaderValue map for the boot class loader */ private static final ConcurrentHashMap CLASS_LOADER_VALUE_MAP = new ConcurrentHashMap<>(); diff --git a/src/java.base/share/classes/jdk/internal/loader/BuiltinClassLoader.java b/src/java.base/share/classes/jdk/internal/loader/BuiltinClassLoader.java --- a/src/java.base/share/classes/jdk/internal/loader/BuiltinClassLoader.java +++ b/src/java.base/share/classes/jdk/internal/loader/BuiltinClassLoader.java @@ -91,7 +91,6 @@ * class loader to delegate to the application class loader, important with * upgraded modules defined to the platform class loader. */ - public class BuiltinClassLoader extends SecureClassLoader { @@ -100,10 +99,10 @@ throw new InternalError("Unable to register as parallel capable"); } - // parent ClassLoader + /** parent ClassLoader */ private final BuiltinClassLoader parent; - // the URL class path or null if there is no class path + /** the URL class path, or null if there is no class path */ private final URLClassPath ucp; diff --git a/src/java.base/share/classes/jdk/internal/loader/ClassLoaders.java b/src/java.base/share/classes/jdk/internal/loader/ClassLoaders.java --- a/src/java.base/share/classes/jdk/internal/loader/ClassLoaders.java +++ b/src/java.base/share/classes/jdk/internal/loader/ClassLoaders.java @@ -56,10 +56,11 @@ // Creates the built-in class loaders. static { // -Xbootclasspath/a or -javaagent with Boot-Class-Path attribute - String s = VM.getSavedProperty("jdk.boot.class.path.append"); - BOOT_LOADER = new BootClassLoader((s != null && s.length() > 0) - ? new URLClassPath(s, true) - : null); + String append = VM.getSavedProperty("jdk.boot.class.path.append"); + BOOT_LOADER = new BootClassLoader( + (append != null && append.length() > 0) + ? new URLClassPath(append, true) + : null); PLATFORM_LOADER = new PlatformClassLoader(BOOT_LOADER); // A class path is required when no main module is specified. @@ -69,8 +70,8 @@ // the empty string and instead treat it as unspecified. String cp = System.getProperty("java.class.path"); if (cp == null || cp.length() == 0) { - String mainMid = System.getProperty("jdk.module.main"); - cp = (mainMid == null) ? "" : null; + String mainModuleName = System.getProperty("jdk.module.main"); + cp = (mainModuleName == null) ? "" : null; } URLClassPath ucp = new URLClassPath(cp, false); APP_LOADER = new AppClassLoader(PLATFORM_LOADER, ucp); diff --git a/src/java.base/share/classes/jdk/internal/loader/Loader.java b/src/java.base/share/classes/jdk/internal/loader/Loader.java --- a/src/java.base/share/classes/jdk/internal/loader/Loader.java +++ b/src/java.base/share/classes/jdk/internal/loader/Loader.java @@ -63,7 +63,6 @@ import jdk.internal.misc.SharedSecrets; import jdk.internal.module.Resources; - /** * A class loader that loads classes and resources from a collection of * modules, or from a single module where the class loader is a member @@ -84,34 +83,36 @@ * @see ModuleLayer#defineModulesWithOneLoader * @see ModuleLayer#defineModulesWithManyLoaders */ - public final class Loader extends SecureClassLoader { static { ClassLoader.registerAsParallelCapable(); } - // the loader pool is in a pool, can be null + /** the loader pool is in a pool, can be null */ private final LoaderPool pool; - // parent ClassLoader, can be null + /** parent ClassLoader, can be null */ private final ClassLoader parent; - // maps a module name to a module reference + /** maps a module name to a module reference */ private final Map nameToModule; - // maps package name to a module loaded by this class loader + /** maps package name to a module loaded by this class loader */ private final Map localPackageToModule; - // maps package name to a remote class loader, populated post initialization + /** + * maps package name to a remote class loader, populated post + * initialization + */ private final Map remotePackageToLoader = new ConcurrentHashMap<>(); - // maps a module reference to a module reader, populated lazily + /** maps a module reference to a module reader, populated lazily */ private final Map moduleToReader = new ConcurrentHashMap<>(); - // ACC used when loading classes and resources */ + /** ACC used when loading classes and resources */ private final AccessControlContext acc; /** diff --git a/src/java.base/share/classes/jdk/internal/loader/LoaderPool.java b/src/java.base/share/classes/jdk/internal/loader/LoaderPool.java --- a/src/java.base/share/classes/jdk/internal/loader/LoaderPool.java +++ b/src/java.base/share/classes/jdk/internal/loader/LoaderPool.java @@ -37,10 +37,9 @@ * * @see ModuleLayer#defineModulesWithManyLoaders */ - public final class LoaderPool { - // maps module names to class loaders + /** Maps module names to class loaders. */ private final Map loaders; @@ -83,4 +82,3 @@ } } - diff --git a/src/java.base/share/classes/jdk/internal/loader/URLClassPath.java b/src/java.base/share/classes/jdk/internal/loader/URLClassPath.java --- a/src/java.base/share/classes/jdk/internal/loader/URLClassPath.java +++ b/src/java.base/share/classes/jdk/internal/loader/URLClassPath.java @@ -43,6 +43,7 @@ import java.security.AccessController; import java.security.CodeSigner; import java.security.Permission; +import java.security.PrivilegedActionException; import java.security.PrivilegedExceptionAction; import java.security.cert.Certificate; import java.util.ArrayList; @@ -99,27 +100,30 @@ DISABLE_ACC_CHECKING = p != null ? p.equals("true") || p.equals("") : false; } - /* The original search path of URLs. */ + /** The original search path of URLs. */ private final List path; - /* The stack of unopened URLs */ + /** The stack of unopened URLs. */ private final Stack urls = new Stack<>(); - /* The resulting search path of Loaders */ + /** The resulting search path of Loaders. */ private final ArrayList loaders = new ArrayList<>(); - /* Map of each URL opened to its corresponding Loader */ + /** Map of each URL opened to its corresponding Loader. */ private final HashMap lmap = new HashMap<>(); - /* The jar protocol handler to use when creating new URLs */ + /** The jar protocol handler to use when creating new URLs. */ private final URLStreamHandler jarHandler; - /* Whether this URLClassLoader has been closed yet */ + /** Whether this URLClassLoader has been closed yet. */ private boolean closed = false; - /* The context to be used when loading classes and resources. If non-null - * this is the context that was captured during the creation of the - * URLClassLoader. null implies no additional security restrictions. */ + /** + * The context to be used when loading classes and resources. If + * non-null this is the context that was captured during the creation + * of the URLClassLoader. null implies no additional security + * restrictions. + */ private final AccessControlContext acc; /** @@ -209,7 +213,7 @@ try { loader.close(); } catch (IOException e) { - result.add (e); + result.add(e); } } closed = true; @@ -272,7 +276,7 @@ * * @param name the name of the resource * @param check whether to perform a security check - * @return a URL for the resource, or null + * @return a {@code URL} for the resource, or {@code null} * if the resource could not be found. */ public URL findResource(String name, boolean check) { @@ -403,7 +407,7 @@ return getResources(name, true); } - /* + /** * Returns the Loader at the specified position in the URL search * path. The URLs are opened and expanded as needed. Returns null * if the specified index is out of range. @@ -460,13 +464,13 @@ return loaders.get(index); } - /* + /** * Returns the Loader for the specified base URL. */ private Loader getLoader(final URL url) throws IOException { try { - return java.security.AccessController.doPrivileged( - new java.security.PrivilegedExceptionAction<>() { + return AccessController.doPrivileged( + new PrivilegedExceptionAction<>() { public Loader run() throws IOException { String protocol = url.getProtocol(); // lower cased in URL String file = url.getFile(); @@ -487,7 +491,7 @@ } } }, acc); - } catch (java.security.PrivilegedActionException pae) { + } catch (PrivilegedActionException pae) { throw (IOException)pae.getException(); } } @@ -500,7 +504,7 @@ return h instanceof sun.net.www.protocol.jar.Handler; } - /* + /** * Pushes the specified URLs onto the list of unopened URLs. */ private void push(URL[] us) { @@ -511,9 +515,9 @@ } } - /* - * Check whether the resource URL should be returned. - * Return null on security check failure. + /** + * Checks whether the resource URL should be returned. + * Returns null on security check failure. * Called by java.net.URLClassLoader. */ public static URL checkURL(URL url) { @@ -527,9 +531,9 @@ return url; } - /* - * Check whether the resource URL should be returned. - * Throw exception on failure. + /** + * Checks whether the resource URL should be returned. + * Throws exception on failure. * Called internally within this file. */ public static void check(URL url) throws IOException { @@ -571,14 +575,14 @@ private final URL base; private JarFile jarfile; // if this points to a jar file - /* + /** * Creates a new Loader for the specified URL. */ Loader(URL url) { base = url; } - /* + /** * Returns the base URL for this Loader. */ URL getBaseURL() { @@ -658,7 +662,7 @@ }; } - /* + /** * Returns the Resource for the specified name, or null if not * found or the caller does not have the permission to get the * resource. @@ -667,9 +671,9 @@ return getResource(name, true); } - /* - * close this loader and release all resources - * method overridden in sub-classes + /** + * Closes this loader and release all resources. + * Method overridden in sub-classes. */ @Override public void close() throws IOException { @@ -678,7 +682,7 @@ } } - /* + /** * Returns the local class path for this loader, or null if none. */ URL[] getClassPath() throws IOException { @@ -686,7 +690,7 @@ } } - /* + /** * Nested class used to represent a Loader of resources from a JAR URL. */ static class JarLoader extends Loader { @@ -700,7 +704,7 @@ private static final JavaUtilZipFileAccess zipAccess = SharedSecrets.getJavaUtilZipFileAccess(); - /* + /** * Creates a new JarLoader for the specified URL referring to * a JAR file. */ @@ -740,8 +744,8 @@ private void ensureOpen() throws IOException { if (jar == null) { try { - java.security.AccessController.doPrivileged( - new java.security.PrivilegedExceptionAction<>() { + AccessController.doPrivileged( + new PrivilegedExceptionAction<>() { public Void run() throws IOException { if (DEBUG) { System.err.println("Opening " + csu); @@ -757,7 +761,7 @@ // if the same URL occurs later on the main class path. We set // Loader to null here to avoid creating a Loader for each // URL until we actually need to try to load something from them. - for(int i = 0; i < jarfiles.length; i++) { + for (int i = 0; i < jarfiles.length; i++) { try { URL jarURL = new URL(csu, jarfiles[i]); // If a non-null loader already exists, leave it alone. @@ -773,13 +777,13 @@ return null; } }, acc); - } catch (java.security.PrivilegedActionException pae) { + } catch (PrivilegedActionException pae) { throw (IOException)pae.getException(); } } } - /* Throws if the given jar file is does not start with the correct LOC */ + /** Throws if the given jar file is does not start with the correct LOC */ static JarFile checkJar(JarFile jar) throws IOException { if (System.getSecurityManager() != null && !DISABLE_JAR_CHECKING && !zipAccess.startsWithLocHeader(jar)) { @@ -811,7 +815,7 @@ return checkJar(jarFile); } - /* + /** * Returns the index of this JarLoader if it exists. */ JarIndex getIndex() { @@ -823,7 +827,7 @@ return index; } - /* + /** * Creates the resource and if the check flag is set to true, checks if * is its okay to return the resource. */ @@ -869,14 +873,14 @@ } - /* + /** * Returns true iff at least one resource in the jar file has the same * package name as that of the specified resource name. */ boolean validIndex(final String name) { String packageName = name; int pos; - if((pos = name.lastIndexOf('/')) != -1) { + if ((pos = name.lastIndexOf('/')) != -1) { packageName = name.substring(0, pos); } @@ -886,7 +890,7 @@ while (enum_.hasMoreElements()) { entry = enum_.nextElement(); entryName = entry.getName(); - if((pos = entryName.lastIndexOf('/')) != -1) + if ((pos = entryName.lastIndexOf('/')) != -1) entryName = entryName.substring(0, pos); if (entryName.equals(packageName)) { return true; @@ -895,7 +899,7 @@ return false; } - /* + /** * Returns the URL for a resource with the specified name */ @Override @@ -907,7 +911,7 @@ return null; } - /* + /** * Returns the JAR Resource for the specified name. */ @Override @@ -928,12 +932,12 @@ return getResource(name, check, visited); } - /* + /** * Version of getResource() that tracks the jar files that have been * visited by linking through the index files. This helper method uses * a HashSet to store the URLs of jar files that have been searched and * uses it to avoid going into an infinite loop, looking for a - * non-existent resource + * non-existent resource. */ Resource getResource(final String name, boolean check, Set visited) { @@ -945,14 +949,14 @@ /* If there no jar files in the index that can potential contain * this resource then return immediately. */ - if((jarFilesList = index.get(name)) == null) + if ((jarFilesList = index.get(name)) == null) return null; do { int size = jarFilesList.size(); jarFiles = jarFilesList.toArray(new String[size]); /* loop through the mapped jar file list */ - while(count < size) { + while (count < size) { String jarName = jarFiles[count++]; JarLoader newLoader; final URL url; @@ -977,7 +981,7 @@ * account the relative path. */ JarIndex newIndex = newLoader.getIndex(); - if(newIndex != null) { + if (newIndex != null) { int pos = jarName.lastIndexOf('/'); newIndex.merge(this.index, (pos == -1 ? null : jarName.substring(0, pos + 1))); @@ -986,7 +990,7 @@ /* put it in the global hashtable */ lmap.put(urlNoFragString, newLoader); } - } catch (java.security.PrivilegedActionException pae) { + } catch (PrivilegedActionException pae) { continue; } catch (MalformedURLException e) { continue; @@ -1029,7 +1033,7 @@ /* Process the index of the new loader */ - if((res = newLoader.getResource(name, check, visited)) + if ((res = newLoader.getResource(name, check, visited)) != null) { return res; } @@ -1039,12 +1043,12 @@ jarFilesList = index.get(name); // If the count is unchanged, we are done. - } while(count < jarFilesList.size()); + } while (count < jarFilesList.size()); return null; } - /* + /** * Returns the JAR file local class path, or null if none. */ @Override @@ -1071,7 +1075,7 @@ return null; } - /* + /** * Parses value of the Class-Path manifest attribute and returns * an array of URLs relative to the specified base URL. */ @@ -1090,12 +1094,12 @@ } } - /* + /** * Nested class used to represent a loader of classes and resources * from a file URL that refers to a directory. */ private static class FileLoader extends Loader { - /* Canonicalized File */ + /** Canonicalized File */ private File dir; FileLoader(URL url) throws IOException { @@ -1108,7 +1112,7 @@ dir = (new File(path)).getCanonicalFile(); } - /* + /** * Returns the URL for a resource with the specified name */ @Override