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
This commit is contained in:
parent
a834e70bc5
commit
8ac4bd3706
|
@ -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>
|
2004-09-24 Guilhem Lavaux <guilhem@kaffe.org>
|
||||||
|
|
||||||
* java/net/URL.java
|
* java/net/URL.java
|
||||||
|
|
|
@ -39,6 +39,8 @@ exception statement from your version. */
|
||||||
package java.net;
|
package java.net;
|
||||||
|
|
||||||
import gnu.java.net.URLParseError;
|
import gnu.java.net.URLParseError;
|
||||||
|
import java.security.AccessController;
|
||||||
|
import java.security.PrivilegedAction;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.ObjectInputStream;
|
import java.io.ObjectInputStream;
|
||||||
|
@ -124,6 +126,9 @@ public final class URL implements Serializable
|
||||||
private static final String DEFAULT_SEARCH_PATH =
|
private static final String DEFAULT_SEARCH_PATH =
|
||||||
"gnu.java.net.protocol|gnu.inet";
|
"gnu.java.net.protocol|gnu.inet";
|
||||||
|
|
||||||
|
// Cached System ClassLoader
|
||||||
|
private static ClassLoader systemClassLoader;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name of the protocol for this URL.
|
* The name of the protocol for this URL.
|
||||||
* The protocol is always stored in lower case.
|
* 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.
|
// Finally loop through our search path looking for a match.
|
||||||
StringTokenizer pkgPrefix = new StringTokenizer(ph_search_path, "|");
|
StringTokenizer pkgPrefix = new StringTokenizer(ph_search_path, "|");
|
||||||
|
|
||||||
|
// Cache the systemClassLoader
|
||||||
|
if (systemClassLoader == null)
|
||||||
|
{
|
||||||
|
systemClassLoader = (ClassLoader) AccessController.doPrivileged
|
||||||
|
(new PrivilegedAction() {
|
||||||
|
public Object run() {
|
||||||
|
return ClassLoader.getSystemClassLoader();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
String clsName =
|
|
||||||
(pkgPrefix.nextToken() + "." + protocol + ".Handler");
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Object obj = Class.forName(clsName).newInstance();
|
// Try to get a class from the system/application
|
||||||
|
// classloader, initialize it, make an instance
|
||||||
if (! (obj instanceof URLStreamHandler))
|
// and try to cast it to a URLStreamHandler.
|
||||||
continue;
|
String clsName =
|
||||||
else
|
(pkgPrefix.nextToken() + "." + protocol + ".Handler");
|
||||||
ph = (URLStreamHandler) obj;
|
Class c = Class.forName(clsName, true, systemClassLoader);
|
||||||
}
|
ph = (URLStreamHandler) c.newInstance();
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
// Can't instantiate; handler still null,
|
|
||||||
// go on to next element.
|
|
||||||
}
|
}
|
||||||
|
catch (Throwable t) { /* ignored */ }
|
||||||
}
|
}
|
||||||
while ((! (ph instanceof URLStreamHandler))
|
while (ph == null && pkgPrefix.hasMoreTokens());
|
||||||
&& pkgPrefix.hasMoreTokens());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the hashtable with the new protocol handler.
|
// Update the hashtable with the new protocol handler.
|
||||||
if (ph != null && cache_handlers)
|
if (ph != null && cache_handlers)
|
||||||
if (ph instanceof URLStreamHandler)
|
ph_cache.put(protocol, ph);
|
||||||
ph_cache.put(protocol, ph);
|
else
|
||||||
else
|
ph = null;
|
||||||
ph = null;
|
|
||||||
|
|
||||||
return ph;
|
return ph;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue