mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-20 11:04:34 +02:00
8129880: Cleanup usage of Class.getResource in jaxp
Reviewed-by: joehw, mchung
This commit is contained in:
parent
e2f4c35479
commit
a89e684eec
5 changed files with 32 additions and 123 deletions
|
@ -418,30 +418,8 @@ class SchemaFactoryFinder {
|
|||
private static final Class<SchemaFactory> SERVICE_CLASS = SchemaFactory.class;
|
||||
|
||||
|
||||
// Used for debugging purposes
|
||||
private static String which( Class<?> clazz ) {
|
||||
return which( clazz.getName(), clazz.getClassLoader() );
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Search the specified classloader for the given classname.</p>
|
||||
*
|
||||
* @param classname the fully qualified name of the class to search for
|
||||
* @param loader the classloader to search
|
||||
*
|
||||
* @return the source location of the resource, or null if it wasn't found
|
||||
*/
|
||||
private static String which(String classname, ClassLoader loader) {
|
||||
|
||||
String classnameAsResource = classname.replace('.', '/') + ".class";
|
||||
|
||||
if( loader==null ) loader = ClassLoader.getSystemClassLoader();
|
||||
|
||||
//URL it = loader.getResource(classnameAsResource);
|
||||
URL it = ss.getResourceAsURL(loader, classnameAsResource);
|
||||
if (it != null) {
|
||||
return it.toString();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return ss.getClassSource(clazz);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -95,46 +95,22 @@ class SecuritySupport {
|
|||
}
|
||||
}
|
||||
|
||||
URL getResourceAsURL(final ClassLoader cl,
|
||||
final String name)
|
||||
{
|
||||
return (URL)
|
||||
AccessController.doPrivileged(new PrivilegedAction() {
|
||||
public Object run() {
|
||||
URL url;
|
||||
if (cl == null) {
|
||||
url = Object.class.getResource(name);
|
||||
} else {
|
||||
url = cl.getResource(name);
|
||||
}
|
||||
return url;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Enumeration getResources(final ClassLoader cl,
|
||||
final String name) throws IOException
|
||||
{
|
||||
try{
|
||||
return (Enumeration)
|
||||
AccessController.doPrivileged(new PrivilegedExceptionAction() {
|
||||
public Object run() throws IOException{
|
||||
Enumeration enumeration;
|
||||
if (cl == null) {
|
||||
enumeration = ClassLoader.getSystemResources(name);
|
||||
} else {
|
||||
enumeration = cl.getResources(name);
|
||||
}
|
||||
return enumeration;
|
||||
}
|
||||
});
|
||||
}catch(PrivilegedActionException e){
|
||||
throw (IOException)e.getException();
|
||||
}
|
||||
// Used for debugging purposes
|
||||
String getClassSource(Class<?> cls) {
|
||||
return AccessController.doPrivileged(new PrivilegedAction<String>() {
|
||||
public String run() {
|
||||
CodeSource cs = cls.getProtectionDomain().getCodeSource();
|
||||
if (cs != null) {
|
||||
return cs.getLocation().toString();
|
||||
} else {
|
||||
return "(no code source)";
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
boolean doesFileExist(final File f) {
|
||||
return ((Boolean)
|
||||
return ((Boolean)
|
||||
AccessController.doPrivileged(new PrivilegedAction() {
|
||||
public Object run() {
|
||||
return new Boolean(f.exists());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue