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
|
@ -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.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,46 +95,22 @@ 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) {
|
} else {
|
||||||
url = Object.class.getResource(name);
|
return "(no code source)";
|
||||||
} 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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean doesFileExist(final File f) {
|
boolean doesFileExist(final File f) {
|
||||||
return ((Boolean)
|
return ((Boolean)
|
||||||
AccessController.doPrivileged(new PrivilegedAction() {
|
AccessController.doPrivileged(new PrivilegedAction() {
|
||||||
public Object run() {
|
public Object run() {
|
||||||
return new Boolean(f.exists());
|
return new Boolean(f.exists());
|
||||||
|
|
|
@ -92,46 +92,22 @@ 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) {
|
} else {
|
||||||
url = Object.class.getResource(name);
|
return "(no code source)";
|
||||||
} 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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean doesFileExist(final File f) {
|
boolean doesFileExist(final File f) {
|
||||||
return ((Boolean)
|
return ((Boolean)
|
||||||
AccessController.doPrivileged(new PrivilegedAction() {
|
AccessController.doPrivileged(new PrivilegedAction() {
|
||||||
public Object run() {
|
public Object run() {
|
||||||
return new Boolean(f.exists());
|
return new Boolean(f.exists());
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue