1
0

More doPriv's around ClassLoader.loadClass and Class.forName

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/logging/trunk@138946 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Richard A. Sitze
2002-12-13 16:48:06 +00:00
parent 7117827bcb
commit d256cb00f7

View File

@@ -1,7 +1,7 @@
/* /*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//logging/src/java/org/apache/commons/logging/LogFactory.java,v 1.16 2002/12/12 20:29:16 rsitze Exp $ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//logging/src/java/org/apache/commons/logging/LogFactory.java,v 1.17 2002/12/13 16:48:06 rsitze Exp $
* $Revision: 1.16 $ * $Revision: 1.17 $
* $Date: 2002/12/12 20:29:16 $ * $Date: 2002/12/13 16:48:06 $
* *
* ==================================================================== * ====================================================================
* *
@@ -87,7 +87,7 @@ import java.util.Properties;
* @author Craig R. McClanahan * @author Craig R. McClanahan
* @author Costin Manolache * @author Costin Manolache
* @author Richard A. Sitze * @author Richard A. Sitze
* @version $Revision: 1.16 $ $Date: 2002/12/12 20:29:16 $ * @version $Revision: 1.17 $ $Date: 2002/12/13 16:48:06 $
*/ */
public abstract class LogFactory { public abstract class LogFactory {
@@ -533,46 +533,55 @@ public abstract class LogFactory {
* @exception LogConfigurationException if a suitable instance * @exception LogConfigurationException if a suitable instance
* cannot be created * cannot be created
*/ */
protected static LogFactory newFactory(String factoryClass, protected static LogFactory newFactory(final String factoryClass,
ClassLoader classLoader) final ClassLoader classLoader)
throws LogConfigurationException throws LogConfigurationException
{ {
Object result = AccessController.doPrivileged(
try { new PrivilegedAction() {
if (classLoader != null) { public Object run() {
try { try {
// first the given class loader param (thread class loader) if (classLoader != null) {
return (LogFactory)classLoader.loadClass(factoryClass).newInstance(); try {
} catch (ClassNotFoundException ex) { // first the given class loader param (thread class loader)
if (classLoader == LogFactory.class.getClassLoader()) { return classLoader.loadClass(factoryClass).newInstance();
// Nothing more to try, onwards. } catch (ClassNotFoundException ex) {
throw ex; if (classLoader == LogFactory.class.getClassLoader()) {
// Nothing more to try, onwards.
throw ex;
}
// ignore exception, continue
} catch (NoClassDefFoundError e) {
if (classLoader == LogFactory.class.getClassLoader()) {
// Nothing more to try, onwards.
throw e;
}
// ignore exception, continue
}
}
/* At this point, either classLoader == null, OR
* classLoader was unable to load factoryClass..
* try the class loader that loaded this class:
* LogFactory.getClassLoader().
*
* Notes:
* a) LogFactory.class.getClassLoader() may return 'null'
* if LogFactory is loaded by the bootstrap classloader.
* b) The Java endorsed library mechanism is instead
* Class.forName(factoryClass);
*/
return (LogFactory)Class.forName(factoryClass).newInstance();
} catch (Exception e) {
return new LogConfigurationException(e);
} }
// ignore exception, continue
} catch (NoClassDefFoundError e) {
if (classLoader == LogFactory.class.getClassLoader()) {
// Nothing more to try, onwards.
throw e;
}
// ignore exception, continue
} }
} });
/* At this point, either classLoader == null, OR if (result instanceof LogConfigurationException)
* classLoader was unable to load factoryClass.. throw (LogConfigurationException)result;
* try the class loader that loaded this class:
* LogFactory.getClassLoader(). return (LogFactory)result;
*
* Notes:
* a) LogFactory.class.getClassLoader() may return 'null'
* if LogFactory is loaded by the bootstrap classloader.
* b) The Java endorsed library mechanism is instead
* Class.forName(factoryClass);
*/
return (LogFactory)Class.forName(factoryClass).newInstance();
} catch (Exception e) {
throw new LogConfigurationException(e);
}
} }
private static InputStream getResourceAsStream(final ClassLoader loader, private static InputStream getResourceAsStream(final ClassLoader loader,