< prev index next >

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

Print this page
imported patch classloader-cleanup

*** 324,335 **** * 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) { return new Enumeration<>() { private int index = 0; private URL url = null; private boolean next() { --- 324,334 ---- * 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(String name, boolean check) { return new Enumeration<>() { private int index = 0; private URL url = null; private boolean next() {
*** 371,382 **** * 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) { return new Enumeration<>() { private int index = 0; private Resource res = null; private boolean next() { --- 370,380 ---- * 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(String name, boolean check) { return new Enumeration<>() { private int index = 0; private Resource res = null; private boolean next() {
*** 407,417 **** return r; } }; } ! public Enumeration<Resource> getResources(final String name) { return getResources(name, true); } /* * Returns the Loader at the specified position in the URL search --- 405,415 ---- return r; } }; } ! public Enumeration<Resource> getResources(String name) { return getResources(name, true); } /* * Returns the Loader at the specified position in the URL search
*** 535,547 **** } /* * 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) { URLConnection urlConnection = url.openConnection(); Permission perm = urlConnection.getPermission(); if (perm != null) { --- 533,544 ---- } /* * Checks whether the resource URL should be returned. * Throws exception on failure. */ ! 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,580 **** } } } /** ! * Nested class used to represent 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 --- 566,576 ---- } } } /** ! * 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,678 **** /* * 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) { return getResource(name, true); } /* * Closes this loader and release all resources. --- 664,674 ---- /* * 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(String name) { return getResource(name, true); } /* * Closes this loader and release all resources.
*** 692,702 **** return null; } } /* ! * Nested class used to represent a Loader of resources from a JAR URL. */ static class JarLoader extends Loader { private JarFile jar; private final URL csu; private JarIndex index; --- 688,698 ---- return null; } } /* ! * A Loader of resources from a JAR URL. */ static class JarLoader extends Loader { private JarFile jar; private final URL csu; private JarIndex index;
*** 724,744 **** ensureOpen(); } @Override ! 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 () { return jar; } private boolean isOptimizable(URL url) { return "file".equals(url.getProtocol()); --- 720,740 ---- ensureOpen(); } @Override ! 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() { return jar; } private boolean isOptimizable(URL url) { return "file".equals(url.getProtocol());
*** 784,794 **** throw (IOException)pae.getException(); } } } ! /* 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)) { IOException x = new IOException("Invalid Jar file"); try { --- 780,790 ---- throw (IOException)pae.getException(); } } } ! /* 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,840 **** return index; } /* * Creates the resource and if the check flag is set to true, checks if ! * is its okay to return the resource. */ Resource checkResource(final String name, boolean check, final JarEntry entry) { final URL url; --- 826,836 ---- return index; } /* * Creates the resource and if the check flag is set to true, checks if ! * is it's okay to return the resource. */ Resource checkResource(final String name, boolean check, final JarEntry entry) { final URL url;
*** 903,913 **** } return false; } /* ! * 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) { --- 899,909 ---- } return false; } /* ! * 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,1045 **** if (visitedURL || newLoader == this || newLoader.getIndex() == null) { continue; } ! /* Process the index of the new loader ! */ if ((res = newLoader.getResource(name, check, visited)) != null) { return res; } } --- 1030,1040 ---- if (visitedURL || newLoader == this || newLoader.getIndex() == null) { continue; } ! // Process the index of the new loader if ((res = newLoader.getResource(name, check, visited)) != null) { return res; } }
*** 1106,1116 **** } return urls; } /* ! * Return 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 { --- 1101,1111 ---- } return urls; } /* ! * 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,1149 **** return null; } } /* ! * 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 */ private File dir; --- 1133,1143 ---- return null; } } /* ! * 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,1184 **** path = ParseUtil.decode(path); dir = (new File(path)).getCanonicalFile(); } /* ! * 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) { return rsc.getURL(); } return null; } @Override ! Resource getResource(final String name, boolean check) { ! final URL url; try { URL normalizedBase = new URL(getBaseURL(), "."); ! url = new URL(getBaseURL(), ParseUtil.encodePath(name, false)); ! if (url.getFile().startsWith(normalizedBase.getFile()) == false) { // requested resource had ../..'s in path return null; } if (check) --- 1150,1178 ---- path = ParseUtil.decode(path); dir = (new File(path)).getCanonicalFile(); } /* ! * Returns the URL for a resource with the specified name. */ @Override ! URL findResource(String name, boolean check) { Resource rsc = getResource(name, check); if (rsc != null) { return rsc.getURL(); } return null; } @Override ! Resource getResource(String name, boolean check) { try { URL normalizedBase = new URL(getBaseURL(), "."); ! final URL url = new URL( ! getBaseURL(), ParseUtil.encodePath(name, false)); ! if (!url.getFile().startsWith(normalizedBase.getFile())) { // requested resource had ../..'s in path return null; } if (check)
*** 1186,1196 **** final File file; if (name.indexOf("..") != -1) { file = (new File(dir, name.replace('/', File.separatorChar))) .getCanonicalFile(); ! if ( !((file.getPath()).startsWith(dir.getPath())) ) { /* outside of base dir */ return null; } } else { file = new File(dir, name.replace('/', File.separatorChar)); --- 1180,1190 ---- final File file; if (name.indexOf("..") != -1) { file = (new File(dir, name.replace('/', File.separatorChar))) .getCanonicalFile(); ! if (!file.getPath().startsWith(dir.getPath())) { /* outside of base dir */ return null; } } else { file = new File(dir, name.replace('/', File.separatorChar));
< prev index next >