From 766d8320d89a65c9793a14fe1f649d253f2e033b Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Fri, 17 Jan 2003 19:14:06 +0000 Subject: 2003-01-17 Mark Wielaard Jeroen Frijters * java/net/URLClassLoader.java (Resource.getCodeSource): Fix check certs == null. (getCanonicalFileURL): Removed method. (JarURLLoader): Don't call removed method. (FileURLLoader): Likewise. (FileURLLoader.getResource): Don't canonicalize file name. 2003-01-17 Mark Wielaard * java/lang/ClassLoader.java (normalize): Removed. (getResource): Don't call normalize. (getResources): Likewise. --- ChangeLog | 16 +++++++++++++++ java/lang/ClassLoader.java | 40 ------------------------------------- java/net/URLClassLoader.java | 47 +++++--------------------------------------- 3 files changed, 21 insertions(+), 82 deletions(-) diff --git a/ChangeLog b/ChangeLog index 03988b562..34c7c4574 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2003-01-17 Mark Wielaard + Jeroen Frijters + + * java/net/URLClassLoader.java (Resource.getCodeSource): + Fix check certs == null. + (getCanonicalFileURL): Removed method. + (JarURLLoader): Don't call removed method. + (FileURLLoader): Likewise. + (FileURLLoader.getResource): Don't canonicalize file name. + +2003-01-17 Mark Wielaard + + * java/lang/ClassLoader.java (normalize): Removed. + (getResource): Don't call normalize. + (getResources): Likewise. + 2003-01-17 Mark Wielaard * NEWS: Describe java.io.(VM)ObjectStreamClass. diff --git a/java/lang/ClassLoader.java b/java/lang/ClassLoader.java index e6ffb5fe8..53a16e460 100644 --- a/java/lang/ClassLoader.java +++ b/java/lang/ClassLoader.java @@ -516,7 +516,6 @@ public abstract class ClassLoader */ public URL getResource(String name) { - name = normalize(name); URL result; if (parent == null) @@ -551,7 +550,6 @@ public abstract class ClassLoader */ public final Enumeration getResources(String name) throws IOException { - name = normalize(name); Enumeration parentResources; if (parent == null) parentResources = VMClassLoader.getResources(name); @@ -560,44 +558,6 @@ public abstract class ClassLoader return new DoubleEnumeration(parentResources, findResources(name)); } - /** - * Normalizes a resource path name. This removes all ./ from the start and - * all further '//', "/../" and "/./" from the given name. - */ - private static String normalize(String resource) - { - while (resource.startsWith("./")) - resource = resource.substring(2); - - int index = resource.indexOf("//"); - while (index != -1) - { - resource = resource.substring(0, index) + resource.substring(index+1); - index = resource.indexOf("//"); - } - - index = resource.indexOf("/../"); - while (index != -1) - { - int last = resource.lastIndexOf('/', index-1); - if (last != -1) - resource = resource.substring(0, last+1) - + resource.substring(index+4); - else - resource = resource.substring(index+4); - index = resource.indexOf("/../"); - } - - index = resource.indexOf("/./"); - while (index != -1) - { - resource = resource.substring(0, index) + resource.substring(index+2); - index = resource.indexOf("/./"); - } - - return resource; - } - /** * Called whenever all locations of a named resource are needed. * It is called by getResources() after it has called diff --git a/java/net/URLClassLoader.java b/java/net/URLClassLoader.java index 0bc19d011..d7fc77f8a 100644 --- a/java/net/URLClassLoader.java +++ b/java/net/URLClassLoader.java @@ -238,7 +238,7 @@ public class URLClassLoader extends SecureClassLoader CodeSource getCodeSource() { Certificate[] certs = getCertificates(); - if (certs != null) + if (certs == null) return loader.noCertCodeSource; else return new CodeSource(loader.baseURL, certs); @@ -271,48 +271,18 @@ public class URLClassLoader extends SecureClassLoader abstract InputStream getInputStream() throws IOException; } - /** - * Returns the given URL with a canonicalized file path name when it - * is has the file protocol. Otherwise (or when the file part of the - * URL couldn't be canonicalized) it returns the original String. - * It makes sure that if the original file part ended with a file - * separator that the new file part also ends with a separator. - */ - static URL getCanonicalFileURL(URL url) - { - if ("file".equals(url.getProtocol())) - { - try - { - String f = url.getFile(); - File file = new File(f).getCanonicalFile(); - String cf = file.toString(); - String sep = File.separator; - if (f.endsWith(sep) && !cf.endsWith(sep)) - { - cf += "/"; - } - url = new URL("file", "", cf); - } - catch (IOException ignore) - { - } - } - return url; - } - /** * A JarURLLoader is a type of URLLoader * only loading from jar url. */ final static class JarURLLoader extends URLLoader { - final JarFile jarfile; // The canonical jar file for this url + final JarFile jarfile; // The jar file for this url final URL baseJarURL; // Base jar: url for all resources loaded from jar public JarURLLoader(URLClassLoader classloader, URL baseURL) { - super(classloader, getCanonicalFileURL(baseURL)); + super(classloader, baseURL); // cache url prefix for all resources in this jar url String external = baseURL.toExternalForm(); @@ -495,11 +465,11 @@ public class URLClassLoader extends SecureClassLoader */ final static class FileURLLoader extends URLLoader { - File dir; //the canonical file for this file url + File dir; //the file for this file url FileURLLoader(URLClassLoader classloader, URL url) { - super(classloader, getCanonicalFileURL(url)); + super(classloader, url); dir = new File(baseURL.getFile()); } @@ -507,13 +477,6 @@ public class URLClassLoader extends SecureClassLoader Resource getResource(String name) { File file = new File(dir, name); - try - { - file = file.getCanonicalFile(); - } - catch (IOException ignore) - { - } if (file.exists() && !file.isDirectory()) return new FileResource(this, name, file); return null; -- cgit v1.2.1