# HG changeset patch # User martin # Date 1546624829 28800 # Fri Jan 04 10:00:29 2019 -0800 # Node ID b10642221cc803a157a100740a7f38b4795ff5ed # Parent 902ca4b1dba31078722877f897094adfed68bb73 imported patch classloader-cleanup diff --git a/src/java.base/share/classes/java/lang/Module.java b/src/java.base/share/classes/java/lang/Module.java --- a/src/java.base/share/classes/java/lang/Module.java +++ b/src/java.base/share/classes/java/lang/Module.java @@ -418,12 +418,12 @@ // -- exported and open packages -- - // the packages are open to other modules, can be null - // if the value contains EVERYONE_MODULE then the package is open to all + // the packages that are open to other modules, can be null + // if a value contains EVERYONE_MODULE then the package is open to all private volatile Map> openPackages; - // the packages that are exported, can be null - // if the value contains EVERYONE_MODULE then the package is exported to all + // the packages that are exported to other modules, can be null + // if a value contains EVERYONE_MODULE then the package is exported to all private volatile Map> exportedPackages; /** diff --git a/src/java.base/share/classes/java/net/URL.java b/src/java.base/share/classes/java/net/URL.java --- a/src/java.base/share/classes/java/net/URL.java +++ b/src/java.base/share/classes/java/net/URL.java @@ -1026,7 +1026,7 @@ /** * Returns a {@link java.net.URI} equivalent to this URL. - * This method functions in the same way as {@code new URI (this.toString())}. + * This method functions in the same way as {@code new URI(this.toString())}. *

Note, any URL instance that complies with RFC 2396 can be converted * to a URI. However, some URLs that are not strictly in compliance * can not be converted to a URI. @@ -1038,7 +1038,7 @@ * @since 1.5 */ public URI toURI() throws URISyntaxException { - return new URI (toString()); + return new URI(toString()); } /** 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 @@ -326,8 +326,7 @@ * @param name the resource name * @return an Enumeration of all the urls having the specified name */ - public Enumeration findResources(final String name, - final boolean check) { + public Enumeration findResources(String name, boolean check) { return new Enumeration<>() { private int index = 0; private URL url = null; @@ -373,8 +372,7 @@ * @param name the resource name * @return an Enumeration of all the resources having the specified name */ - public Enumeration getResources(final String name, - final boolean check) { + public Enumeration getResources(String name, boolean check) { return new Enumeration<>() { private int index = 0; private Resource res = null; @@ -409,7 +407,7 @@ }; } - public Enumeration getResources(final String name) { + public Enumeration getResources(String name) { return getResources(name, true); } @@ -537,9 +535,8 @@ /* * 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 { + private static void check(URL url) throws IOException { SecurityManager security = System.getSecurityManager(); if (security != null) { URLConnection urlConnection = url.openConnection(); @@ -571,8 +568,7 @@ } /** - * Nested class used to represent a loader of resources and classes - * from a base URL. + * A loader of resources and classes from a base URL. */ private static class Loader implements Closeable { private final URL base; @@ -670,7 +666,7 @@ * found or the caller does not have the permission to get the * resource. */ - Resource getResource(final String name) { + Resource getResource(String name) { return getResource(name, true); } @@ -694,7 +690,7 @@ } /* - * Nested class used to represent a Loader of resources from a JAR URL. + * A Loader of resources from a JAR URL. */ static class JarLoader extends Loader { private JarFile jar; @@ -726,7 +722,7 @@ } @Override - public void close () throws IOException { + public void close() throws IOException { // closing is synchronized at higher level if (!closed) { closed = true; @@ -736,7 +732,7 @@ } } - JarFile getJarFile () { + JarFile getJarFile() { return jar; } @@ -786,7 +782,7 @@ } } - /* Throws if the given jar file is does not start with the correct LOC */ + /* Throws if the given jar file does not start with the correct LOC */ static JarFile checkJar(JarFile jar) throws IOException { if (System.getSecurityManager() != null && !DISABLE_JAR_CHECKING && !zipAccess.startsWithLocHeader(jar)) { @@ -832,7 +828,7 @@ /* * Creates the resource and if the check flag is set to true, checks if - * is its okay to return the resource. + * is it's okay to return the resource. */ Resource checkResource(final String name, boolean check, final JarEntry entry) { @@ -905,7 +901,7 @@ } /* - * Returns the URL for a resource with the specified name + * Returns the URL for a resource with the specified name. */ @Override URL findResource(final String name, boolean check) { @@ -1036,8 +1032,7 @@ continue; } - /* Process the index of the new loader - */ + // Process the index of the new loader if ((res = newLoader.getResource(name, check, visited)) != null) { return res; @@ -1108,7 +1103,7 @@ } /* - * Return a URL for the given path resolved against the base URL, or + * Returns a URL for the given path resolved against the base URL, or * null if the resulting URL is invalid. */ static URL safeResolve(URL base, String path) { @@ -1140,8 +1135,7 @@ } /* - * Nested class used to represent a loader of classes and resources - * from a file URL that refers to a directory. + * A loader of classes and resources from a file URL that refers to a directory. */ private static class FileLoader extends Loader { /* Canonicalized File */ @@ -1158,10 +1152,10 @@ } /* - * Returns the URL for a resource with the specified name + * Returns the URL for a resource with the specified name. */ @Override - URL findResource(final String name, boolean check) { + URL findResource(String name, boolean check) { Resource rsc = getResource(name, check); if (rsc != null) { return rsc.getURL(); @@ -1170,13 +1164,13 @@ } @Override - Resource getResource(final String name, boolean check) { - final URL url; + Resource getResource(String name, boolean check) { try { URL normalizedBase = new URL(getBaseURL(), "."); - url = new URL(getBaseURL(), ParseUtil.encodePath(name, false)); + final URL url = new URL( + getBaseURL(), ParseUtil.encodePath(name, false)); - if (url.getFile().startsWith(normalizedBase.getFile()) == false) { + if (!url.getFile().startsWith(normalizedBase.getFile())) { // requested resource had ../..'s in path return null; } @@ -1188,7 +1182,7 @@ if (name.indexOf("..") != -1) { file = (new File(dir, name.replace('/', File.separatorChar))) .getCanonicalFile(); - if ( !((file.getPath()).startsWith(dir.getPath())) ) { + if (!file.getPath().startsWith(dir.getPath())) { /* outside of base dir */ return null; } diff --git a/src/java.base/unix/classes/jdk/internal/loader/FileURLMapper.java b/src/java.base/unix/classes/jdk/internal/loader/FileURLMapper.java --- a/src/java.base/unix/classes/jdk/internal/loader/FileURLMapper.java +++ b/src/java.base/unix/classes/jdk/internal/loader/FileURLMapper.java @@ -30,22 +30,21 @@ import sun.net.www.ParseUtil; /** - * (Solaris) platform specific handling for file: URLs . - * urls must not contain a hostname in the authority field + * (Unix) platform specific handling for file: URLs . + * URLs must not contain a hostname in the authority field * other than "localhost". * * This implementation could be updated to map such URLs - * on to /net/host/... + * on to /net/host/... on system using such an automounter map. * * @author Michael McMahon */ public class FileURLMapper { - - URL url; + final URL url; String path; - public FileURLMapper (URL url) { + public FileURLMapper(URL url) { this.url = url; } @@ -53,8 +52,7 @@ * @return the platform specific path corresponding to the URL * so long as the URL does not contain a hostname in the authority field. */ - - public String getPath () { + public String getPath() { if (path != null) { return path; } @@ -69,13 +67,8 @@ /** * Checks whether the file identified by the URL exists. */ - public boolean exists () { - String s = getPath (); - if (s == null) { - return false; - } else { - File f = new File (s); - return f.exists(); - } + public boolean exists() { + String s = getPath(); + return s != null && new File(s).exists(); } }