[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Fix for bug #9466 (URL.getURLStreamHandler uses wrong classloader)
From: |
Mark Wielaard |
Subject: |
Fix for bug #9466 (URL.getURLStreamHandler uses wrong classloader) |
Date: |
Fri, 02 Jul 2004 00:54:59 +0200 |
Hi,
This hopefully solves "[bugs #9466] java.net.URL.getURLStreamHandler
uses wrong classloader".
2004-07-01 Mark Wielaard <address@hidden>
* java/net/URL.java (systemClassLoader): New static field.
(getURLStreamHandler): Always use system/application classloader
for finding URLStreamhandler. Remove unecessary instanceof checks.
Ran all mauve tests and saw no new regressions.
Committed.
Cheers,
Mark
Index: java/net/URL.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/net/URL.java,v
retrieving revision 1.30
diff -u -r1.30 URL.java
--- java/net/URL.java 23 Apr 2004 17:37:46 -0000 1.30
+++ java/net/URL.java 1 Jul 2004 22:41:44 -0000
@@ -1,5 +1,6 @@
/* URL.java -- Uniform Resource Locator Class
- Copyright (C) 1998, 1999, 2000, 2002, 2003 Free Software Foundation, Inc.
+ Copyright (C) 1998, 1999, 2000, 2002, 2003, 2004
+ Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -38,6 +39,8 @@
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;
@@ -123,6 +126,9 @@
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.
@@ -854,36 +860,39 @@
// 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;
}
signature.asc
Description: This is a digitally signed message part
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Fix for bug #9466 (URL.getURLStreamHandler uses wrong classloader),
Mark Wielaard <=