< 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,50 **** --- 41,51 ---- 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,217 **** List<IOException> result = new LinkedList<>(); for (Loader loader : loaders) { try { loader.close(); } catch (IOException e) { ! result.add (e); } } closed = true; return result; } --- 208,218 ---- List<IOException> result = new LinkedList<>(); for (Loader loader : loaders) { try { loader.close(); } catch (IOException e) { ! result.add(e); } } closed = true; return result; }
*** 270,280 **** * 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> * 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++) { --- 271,281 ---- * 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} 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,474 **** /* * 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<>() { 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)) { --- 464,475 ---- /* * Returns the Loader for the specified base URL. */ private Loader getLoader(final URL url) throws IOException { try { ! 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,495 **** } else { return new JarLoader(url, jarHandler, lmap, acc); } } }, acc); ! } catch (java.security.PrivilegedActionException pae) { throw (IOException)pae.getException(); } } private static final JavaNetURLAccess JNUA --- 486,496 ---- } else { return new JarLoader(url, jarHandler, lmap, acc); } } }, acc); ! } catch (PrivilegedActionException pae) { throw (IOException)pae.getException(); } } private static final JavaNetURLAccess JNUA
*** 510,521 **** } } } /* ! * Check whether the resource URL should be returned. ! * Return null on security check failure. * Called by java.net.URLClassLoader. */ public static URL checkURL(URL url) { if (url != null) { try { --- 511,522 ---- } } } /* ! * 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,537 **** } return url; } /* ! * Check whether the resource URL should be returned. ! * Throw exception on failure. * Called internally within this file. */ public static void check(URL url) throws IOException { SecurityManager security = System.getSecurityManager(); if (security != null) { --- 527,538 ---- } return url; } /* ! * 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,677 **** Resource getResource(final String name) { return getResource(name, true); } /* ! * close this loader and release all resources ! * method overridden in sub-classes */ @Override public void close() throws IOException { if (jarfile != null) { jarfile.close(); --- 667,678 ---- Resource getResource(final String name) { return getResource(name, true); } /* ! * Closes this loader and release all resources. ! * Method overridden in sub-classes. */ @Override public void close() throws IOException { if (jarfile != null) { jarfile.close();
*** 738,749 **** } private void ensureOpen() throws IOException { if (jar == null) { try { ! java.security.AccessController.doPrivileged( ! new java.security.PrivilegedExceptionAction<>() { public Void run() throws IOException { if (DEBUG) { System.err.println("Opening " + csu); Thread.dumpStack(); } --- 739,750 ---- } private void ensureOpen() throws IOException { if (jar == null) { try { ! AccessController.doPrivileged( ! new PrivilegedExceptionAction<>() { public Void run() throws IOException { if (DEBUG) { System.err.println("Opening " + csu); Thread.dumpStack(); }
*** 755,765 **** // 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++) { 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)) { --- 756,766 ---- // 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++) { 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,781 **** } } return null; } }, acc); ! } catch (java.security.PrivilegedActionException pae) { throw (IOException)pae.getException(); } } } --- 772,782 ---- } } return null; } }, acc); ! } catch (PrivilegedActionException pae) { throw (IOException)pae.getException(); } } }
*** 874,894 **** * package name as that of the specified resource name. */ boolean validIndex(final String name) { String packageName = name; int pos; ! 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) entryName = entryName.substring(0, pos); if (entryName.equals(packageName)) { return true; } } --- 875,895 ---- * package name as that of the specified resource name. */ boolean validIndex(final String name) { String packageName = name; int pos; ! 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) entryName = entryName.substring(0, pos); if (entryName.equals(packageName)) { return true; } }
*** 931,941 **** /* * 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 */ Resource getResource(final String name, boolean check, Set<String> visited) { Resource res; String[] jarFiles; --- 932,942 ---- /* * 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. */ Resource getResource(final String name, boolean check, Set<String> visited) { Resource res; String[] jarFiles;
*** 943,960 **** 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) return null; do { int size = jarFilesList.size(); jarFiles = jarFilesList.toArray(new String[size]); /* loop through the mapped jar file list */ ! while(count < size) { String jarName = jarFiles[count++]; JarLoader newLoader; final URL url; try{ --- 944,961 ---- 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) return null; do { int size = jarFilesList.size(); jarFiles = jarFilesList.toArray(new String[size]); /* loop through the mapped jar file list */ ! while (count < size) { String jarName = jarFiles[count++]; JarLoader newLoader; final URL url; try{
*** 975,994 **** /* 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) { 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) { continue; } catch (MalformedURLException e) { continue; } --- 976,995 ---- /* 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) { 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 (PrivilegedActionException pae) { continue; } catch (MalformedURLException e) { continue; }
*** 1027,1047 **** continue; } /* Process the index of the new loader */ ! 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()); return null; } /* --- 1028,1048 ---- continue; } /* Process the index of the new loader */ ! 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()); return null; } /*
< prev index next >