1
0

Enhance the error message produced when the isAssignableFrom() check

in getLogConstructor() fails.  If it is due to the fact that o.a.c.l.Log
is visible more than once (the typical cause), say this explicitly.

PR:  Bugzilla #25156.
Submitted by:  Ralf Hauser <hauser AT acm DOT org>


git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/logging/trunk@139022 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Craig R. McClanahan
2004-03-06 21:52:59 +00:00
parent b7a766054f
commit c69e5fd057

View File

@@ -63,7 +63,7 @@ import org.apache.commons.logging.LogFactory;
* @author Rod Waldhoff
* @author Craig R. McClanahan
* @author Richard A. Sitze
* @version $Revision: 1.32 $ $Date: 2004/03/06 21:25:36 $
* @version $Revision: 1.33 $ $Date: 2004/03/06 21:52:59 $
*/
public class LogFactoryImpl extends LogFactory {
@@ -98,6 +98,13 @@ public class LogFactoryImpl extends LogFactory {
"org.apache.commons.logging.log";
/**
* <p>The name of the {@link Log} interface class.</p>
*/
private static final String LOG_INTERFACE =
"org.apache.commons.logging.Log";
// ----------------------------------------------------- Instance Variables
@@ -362,15 +369,29 @@ public class LogFactoryImpl extends LogFactory {
// Attempt to load the Log implementation class
Class logClass = null;
Class logInterface = null;
try {
logInterface = this.getClass().getClassLoader().loadClass
(LOG_INTERFACE);
logClass = loadClass(logClassName);
if (logClass == null) {
throw new LogConfigurationException
("No suitable Log implementation for " + logClassName);
}
if (!Log.class.isAssignableFrom(logClass)) {
if (!logInterface.isAssignableFrom(logClass)) {
Class interfaces[] = logClass.getInterfaces();
for (int i = 0; i < interfaces.length; i++) {
if (LOG_INTERFACE.equals(interfaces[i].getName())) {
throw new LogConfigurationException
("Class " + logClassName + " does not implement Log");
("Invalid class loader hierarchy. " +
"You have more than one version of '" +
LOG_INTERFACE + "' visible, which is " +
"not allowed.");
}
}
throw new LogConfigurationException
("Class " + logClassName + " does not implement '" +
LOG_INTERFACE + "'.");
}
} catch (Throwable t) {
throw new LogConfigurationException(t);