# HG changeset patch # User dfuchs # Date 1435255597 -7200 # Node ID d6581a7c221f40e7770d7673b1ea0cbe58ad5079 # Parent 4c6b605ceb9f055d604f56187c29fcd8b4275221 8129880: Cleanup usage of Class.getResource in jaxp Reviewed-by: joehw, mchung diff -r 4c6b605ceb9f -r d6581a7c221f jaxp/src/java.xml/share/classes/com/sun/org/apache/xpath/internal/functions/FuncSystemProperty.java --- a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xpath/internal/functions/FuncSystemProperty.java Thu Jun 25 11:06:28 2015 +0200 +++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xpath/internal/functions/FuncSystemProperty.java Thu Jun 25 20:06:37 2015 +0200 @@ -157,7 +157,7 @@ } /** - * 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. */ diff -r 4c6b605ceb9f -r d6581a7c221f jaxp/src/java.xml/share/classes/javax/xml/validation/SchemaFactoryFinder.java --- a/jaxp/src/java.xml/share/classes/javax/xml/validation/SchemaFactoryFinder.java Thu Jun 25 11:06:28 2015 +0200 +++ b/jaxp/src/java.xml/share/classes/javax/xml/validation/SchemaFactoryFinder.java Thu Jun 25 20:06:37 2015 +0200 @@ -418,30 +418,8 @@ private static final Class SERVICE_CLASS = SchemaFactory.class; + // Used for debugging purposes private static String which( Class clazz ) { - return which( clazz.getName(), clazz.getClassLoader() ); - } - - /** - *

Search the specified classloader for the given classname.

- * - * @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); } } diff -r 4c6b605ceb9f -r d6581a7c221f jaxp/src/java.xml/share/classes/javax/xml/validation/SecuritySupport.java --- a/jaxp/src/java.xml/share/classes/javax/xml/validation/SecuritySupport.java Thu Jun 25 11:06:28 2015 +0200 +++ b/jaxp/src/java.xml/share/classes/javax/xml/validation/SecuritySupport.java Thu Jun 25 20:06:37 2015 +0200 @@ -95,46 +95,22 @@ } } - 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() { + 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()); diff -r 4c6b605ceb9f -r d6581a7c221f jaxp/src/java.xml/share/classes/javax/xml/xpath/SecuritySupport.java --- a/jaxp/src/java.xml/share/classes/javax/xml/xpath/SecuritySupport.java Thu Jun 25 11:06:28 2015 +0200 +++ b/jaxp/src/java.xml/share/classes/javax/xml/xpath/SecuritySupport.java Thu Jun 25 20:06:37 2015 +0200 @@ -92,46 +92,22 @@ } } - 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() { + 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()); diff -r 4c6b605ceb9f -r d6581a7c221f jaxp/src/java.xml/share/classes/javax/xml/xpath/XPathFactoryFinder.java --- a/jaxp/src/java.xml/share/classes/javax/xml/xpath/XPathFactoryFinder.java Thu Jun 25 11:06:28 2015 +0200 +++ b/jaxp/src/java.xml/share/classes/javax/xml/xpath/XPathFactoryFinder.java Thu Jun 25 20:06:37 2015 +0200 @@ -414,30 +414,9 @@ private static final Class SERVICE_CLASS = XPathFactory.class; - private static String which( Class clazz ) { - return which( clazz.getName(), clazz.getClassLoader() ); + // Used for debugging purposes + private static String which( Class clazz ) { + return ss.getClassSource(clazz); } - /** - *

Search the specified classloader for the given classname.

- * - * @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; - } - } }