diff options
author | Mark Wielaard <mark@klomp.org> | 2004-09-24 08:02:09 +0000 |
---|---|---|
committer | Michael Koch <mkoch@gcc.gnu.org> | 2004-09-24 08:02:09 +0000 |
commit | 8ac4bd37068ea73ca55ebeaba16ec72709f0d617 (patch) | |
tree | ed0263ee65d59d07f81ce3217917dc217eec3ca1 /libjava | |
parent | a834e70bc5a5ebd751d5782d713da81c95b31766 (diff) | |
download | gcc-8ac4bd37068ea73ca55ebeaba16ec72709f0d617.zip gcc-8ac4bd37068ea73ca55ebeaba16ec72709f0d617.tar.gz gcc-8ac4bd37068ea73ca55ebeaba16ec72709f0d617.tar.bz2 |
URL.java (systemClassLoader): New static field.
2004-09-24 Mark Wielaard <mark@klomp.org>
* java/net/URL.java (systemClassLoader): New static field.
(getURLStreamHandler): Always use system/application classloader
for finding URLStreamhandler. Remove unecessary instanceof checks.
From-SVN: r88018
Diffstat (limited to 'libjava')
-rw-r--r-- | libjava/ChangeLog | 6 | ||||
-rw-r--r-- | libjava/java/net/URL.java | 48 |
2 files changed, 34 insertions, 20 deletions
diff --git a/libjava/ChangeLog b/libjava/ChangeLog index 011bae2..1399a55 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,9 @@ +2004-09-24 Mark Wielaard <mark@klomp.org> + + * java/net/URL.java (systemClassLoader): New static field. + (getURLStreamHandler): Always use system/application classloader + for finding URLStreamhandler. Remove unecessary instanceof checks. + 2004-09-24 Guilhem Lavaux <guilhem@kaffe.org> * java/net/URL.java diff --git a/libjava/java/net/URL.java b/libjava/java/net/URL.java index 71e4358..7bbbd98 100644 --- a/libjava/java/net/URL.java +++ b/libjava/java/net/URL.java @@ -39,6 +39,8 @@ exception statement from your version. */ package java.net; import gnu.java.net.URLParseError; +import java.security.AccessController; +import java.security.PrivilegedAction; import java.io.IOException; import java.io.InputStream; import java.io.ObjectInputStream; @@ -124,6 +126,9 @@ public final class URL implements Serializable private static final String DEFAULT_SEARCH_PATH = "gnu.java.net.protocol|gnu.inet"; + // Cached System ClassLoader + private static ClassLoader systemClassLoader; + /** * The name of the protocol for this URL. * The protocol is always stored in lower case. @@ -890,36 +895,39 @@ public final class URL implements Serializable // Finally loop through our search path looking for a match. StringTokenizer pkgPrefix = new StringTokenizer(ph_search_path, "|"); - do + // Cache the systemClassLoader + if (systemClassLoader == null) { - String clsName = - (pkgPrefix.nextToken() + "." + protocol + ".Handler"); + systemClassLoader = (ClassLoader) AccessController.doPrivileged + (new PrivilegedAction() { + public Object run() { + return ClassLoader.getSystemClassLoader(); + } + }); + } + do + { try { - Object obj = Class.forName(clsName).newInstance(); - - if (! (obj instanceof URLStreamHandler)) - continue; - else - ph = (URLStreamHandler) obj; - } - catch (Exception e) - { - // Can't instantiate; handler still null, - // go on to next element. + // Try to get a class from the system/application + // classloader, initialize it, make an instance + // and try to cast it to a URLStreamHandler. + String clsName = + (pkgPrefix.nextToken() + "." + protocol + ".Handler"); + Class c = Class.forName(clsName, true, systemClassLoader); + ph = (URLStreamHandler) c.newInstance(); } + catch (Throwable t) { /* ignored */ } } - while ((! (ph instanceof URLStreamHandler)) - && pkgPrefix.hasMoreTokens()); + while (ph == null && pkgPrefix.hasMoreTokens()); } // Update the hashtable with the new protocol handler. if (ph != null && cache_handlers) - if (ph instanceof URLStreamHandler) - ph_cache.put(protocol, ph); - else - ph = null; + ph_cache.put(protocol, ph); + else + ph = null; return ph; } |