< prev index next >

src/java.base/share/classes/jdk/internal/loader/URLClassPath.java

Print this page
imported patch classloader-cleanup

@@ -324,12 +324,11 @@
      * Returns an enumeration of the URL objects.
      *
      * @param name the resource name
      * @return an Enumeration of all the urls having the specified name
      */
-    public Enumeration<URL> findResources(final String name,
-                                     final boolean check) {
+    public Enumeration<URL> findResources(String name, boolean check) {
         return new Enumeration<>() {
             private int index = 0;
             private URL url = null;
 
             private boolean next() {

@@ -371,12 +370,11 @@
      * Returns an enumeration of the Resource objects.
      *
      * @param name the resource name
      * @return an Enumeration of all the resources having the specified name
      */
-    public Enumeration<Resource> getResources(final String name,
-                                    final boolean check) {
+    public Enumeration<Resource> getResources(String name, boolean check) {
         return new Enumeration<>() {
             private int index = 0;
             private Resource res = null;
 
             private boolean next() {

@@ -407,11 +405,11 @@
                 return r;
             }
         };
     }
 
-    public Enumeration<Resource> getResources(final String name) {
+    public Enumeration<Resource> getResources(String name) {
         return getResources(name, true);
     }
 
     /*
      * Returns the Loader at the specified position in the URL search

@@ -535,13 +533,12 @@
     }
 
     /*
      * 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();
             Permission perm = urlConnection.getPermission();
             if (perm != null) {

@@ -569,12 +566,11 @@
             }
         }
     }
 
     /**
-     * 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;
         private JarFile jarfile; // if this points to a jar file
 

@@ -668,11 +664,11 @@
         /*
          * Returns the Resource for the specified name, or null if not
          * 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);
         }
 
         /*
          * Closes this loader and release all resources.

@@ -692,11 +688,11 @@
             return null;
         }
     }
 
     /*
-     * 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;
         private final URL csu;
         private JarIndex index;

@@ -724,21 +720,21 @@
 
             ensureOpen();
         }
 
         @Override
-        public void close () throws IOException {
+        public void close() throws IOException {
             // closing is synchronized at higher level
             if (!closed) {
                 closed = true;
                 // in case not already open.
                 ensureOpen();
                 jar.close();
             }
         }
 
-        JarFile getJarFile () {
+        JarFile getJarFile() {
             return jar;
         }
 
         private boolean isOptimizable(URL url) {
             return "file".equals(url.getProtocol());

@@ -784,11 +780,11 @@
                     throw (IOException)pae.getException();
                 }
             }
         }
 
-        /* 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)) {
                 IOException x = new IOException("Invalid Jar file");
                 try {

@@ -830,11 +826,11 @@
             return index;
         }
 
         /*
          * 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) {
 
             final URL url;

@@ -903,11 +899,11 @@
             }
             return false;
         }
 
         /*
-         * 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) {
             Resource rsc = getResource(name, check);
             if (rsc != null) {

@@ -1034,12 +1030,11 @@
                     if (visitedURL || newLoader == this ||
                             newLoader.getIndex() == null) {
                         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;
                     }
                 }

@@ -1106,11 +1101,11 @@
             }
             return urls;
         }
 
         /*
-         * 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) {
             String child = path.replace(File.separatorChar, '/');
             try {

@@ -1138,12 +1133,11 @@
             return null;
         }
     }
 
     /*
-     * 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 */
         private File dir;
 

@@ -1156,29 +1150,29 @@
             path = ParseUtil.decode(path);
             dir = (new File(path)).getCanonicalFile();
         }
 
         /*
-         * 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();
             }
             return null;
         }
 
         @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;
                 }
 
                 if (check)

@@ -1186,11 +1180,11 @@
 
                 final File file;
                 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;
                     }
                 } else {
                     file = new File(dir, name.replace('/', File.separatorChar));
< prev index next >