8129880: Cleanup usage of Class.getResource in jaxp

Reviewed-by: joehw, mchung
This commit is contained in:
Daniel Fuchs 2015-06-25 20:06:37 +02:00
parent e2f4c35479
commit a89e684eec
5 changed files with 32 additions and 123 deletions

View file

@ -157,7 +157,7 @@ public class FuncSystemProperty extends FunctionOneArg
} }
/** /**
* Retrieve a property bundle from a XSLT_PROPERTIES * Retrieve a property bundle from XSLT_PROPERTIES
* *
* @param target The target property bag the file will be placed into. * @param target The target property bag the file will be placed into.
*/ */

View file

@ -418,30 +418,8 @@ class SchemaFactoryFinder {
private static final Class<SchemaFactory> SERVICE_CLASS = SchemaFactory.class; private static final Class<SchemaFactory> SERVICE_CLASS = SchemaFactory.class;
// Used for debugging purposes
private static String which( Class<?> clazz ) { private static String which( Class<?> clazz ) {
return which( clazz.getName(), clazz.getClassLoader() ); return ss.getClassSource(clazz);
}
/**
* <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;
}
} }
} }

View file

@ -95,44 +95,20 @@ class SecuritySupport {
} }
} }
URL getResourceAsURL(final ClassLoader cl, // Used for debugging purposes
final String name) String getClassSource(Class<?> cls) {
{ return AccessController.doPrivileged(new PrivilegedAction<String>() {
return (URL) public String run() {
AccessController.doPrivileged(new PrivilegedAction() { CodeSource cs = cls.getProtectionDomain().getCodeSource();
public Object run() { if (cs != null) {
URL url; return cs.getLocation().toString();
if (cl == null) {
url = Object.class.getResource(name);
} else { } else {
url = cl.getResource(name); return "(no code source)";
} }
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();
}
}
boolean doesFileExist(final File f) { boolean doesFileExist(final File f) {
return ((Boolean) return ((Boolean)
AccessController.doPrivileged(new PrivilegedAction() { AccessController.doPrivileged(new PrivilegedAction() {

View file

@ -92,44 +92,20 @@ class SecuritySupport {
} }
} }
URL getResourceAsURL(final ClassLoader cl, // Used for debugging purposes
final String name) String getClassSource(Class<?> cls) {
{ return AccessController.doPrivileged(new PrivilegedAction<String>() {
return (URL) public String run() {
AccessController.doPrivileged(new PrivilegedAction() { CodeSource cs = cls.getProtectionDomain().getCodeSource();
public Object run() { if (cs != null) {
URL url; return cs.getLocation().toString();
if (cl == null) {
url = Object.class.getResource(name);
} else { } else {
url = cl.getResource(name); return "(no code source)";
} }
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();
}
}
boolean doesFileExist(final File f) { boolean doesFileExist(final File f) {
return ((Boolean) return ((Boolean)
AccessController.doPrivileged(new PrivilegedAction() { AccessController.doPrivileged(new PrivilegedAction() {

View file

@ -414,30 +414,9 @@ class XPathFactoryFinder {
private static final Class<XPathFactory> SERVICE_CLASS = XPathFactory.class; private static final Class<XPathFactory> SERVICE_CLASS = XPathFactory.class;
private static String which( Class clazz ) { // Used for debugging purposes
return which( clazz.getName(), clazz.getClassLoader() ); private static String which( Class<?> clazz ) {
return ss.getClassSource(clazz);
} }
/**
* <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;
}
}
} }