< prev index next >

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

Print this page
8198481: Coding style cleanups for src/java.base/share/classes/jdk/internal/loader
Reviewed-by: alanb, mchung, rriggs

@@ -41,10 +41,11 @@
 import java.security.AccessControlContext;
 import java.security.AccessControlException;
 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;
 import java.util.Arrays;
 import java.util.Collections;

@@ -207,11 +208,11 @@
         List<IOException> result = new LinkedList<>();
         for (Loader loader : loaders) {
             try {
                 loader.close();
             } catch (IOException e) {
-                result.add (e);
+                result.add(e);
             }
         }
         closed = true;
         return result;
     }

@@ -270,11 +271,11 @@
      * Finds the resource with the specified name on the URL search path
      * or null if not found or security check fails.
      *
      * @param name      the name of the resource
      * @param check     whether to perform a security check
-     * @return a <code>URL</code> for the resource, or <code>null</code>
+     * @return a {@code URL} for the resource, or {@code null}
      * if the resource could not be found.
      */
     public URL findResource(String name, boolean check) {
         Loader loader;
         for (int i = 0; (loader = getLoader(i)) != null; i++) {

@@ -463,12 +464,12 @@
     /*
      * 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();
                             if (file != null && file.endsWith("/")) {
                                 if ("file".equals(protocol)) {

@@ -485,11 +486,11 @@
                             } else {
                                 return new JarLoader(url, jarHandler, lmap, acc);
                             }
                         }
                     }, acc);
-        } catch (java.security.PrivilegedActionException pae) {
+        } catch (PrivilegedActionException pae) {
             throw (IOException)pae.getException();
         }
     }
 
     private static final JavaNetURLAccess JNUA

@@ -510,12 +511,12 @@
             }
         }
     }
 
     /*
-     * 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) {
         if (url != null) {
             try {

@@ -526,12 +527,12 @@
         }
         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 {
         SecurityManager security = System.getSecurityManager();
         if (security != null) {

@@ -666,12 +667,12 @@
         Resource getResource(final String name) {
             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 {
             if (jarfile != null) {
                 jarfile.close();

@@ -738,12 +739,12 @@
         }
 
         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);
                                     Thread.dumpStack();
                                 }

@@ -755,11 +756,11 @@
                                 // Add all the dependent URLs to the lmap so that loaders
                                 // will not be created for them by URLClassPath.getLoader(int)
                                 // 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.
                                             String urlNoFragString = URLUtil.urlNoFragString(jarURL);
                                             if (!lmap.containsKey(urlNoFragString)) {

@@ -771,11 +772,11 @@
                                     }
                                 }
                                 return null;
                             }
                         }, acc);
-                } catch (java.security.PrivilegedActionException pae) {
+                } catch (PrivilegedActionException pae) {
                     throw (IOException)pae.getException();
                 }
             }
         }
 

@@ -874,21 +875,21 @@
          * 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);
             }
 
             String entryName;
             ZipEntry entry;
             Enumeration<JarEntry> enum_ = jar.entries();
             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;
                 }
             }

@@ -931,11 +932,11 @@
         /*
          * 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<String> visited) {
             Resource res;
             String[] jarFiles;

@@ -943,18 +944,18 @@
             LinkedList<String> jarFilesList = null;
 
             /* 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;
 
                     try{

@@ -975,20 +976,20 @@
                             /* this newly opened jar file has its own index,
                              * merge it into the parent's index, taking into
                              * 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)));
                             }
 
                             /* put it in the global hashtable */
                             lmap.put(urlNoFragString, newLoader);
                         }
-                    } catch (java.security.PrivilegedActionException pae) {
+                    } catch (PrivilegedActionException pae) {
                         continue;
                     } catch (MalformedURLException e) {
                         continue;
                     }
 

@@ -1027,21 +1028,21 @@
                         continue;
                     }
 
                     /* Process the index of the new loader
                      */
-                    if((res = newLoader.getResource(name, check, visited))
+                    if ((res = newLoader.getResource(name, check, visited))
                             != null) {
                         return res;
                     }
                 }
                 // Get the list of jar files again as the list could have grown
                 // due to merging of index files.
                 jarFilesList = index.get(name);
 
             // If the count is unchanged, we are done.
-            } while(count < jarFilesList.size());
+            } while (count < jarFilesList.size());
             return null;
         }
 
 
         /*
< prev index next >