From c69e5fd057e9d3b9debc486d81f9c144f51bf929 Mon Sep 17 00:00:00 2001 From: "Craig R. McClanahan" Date: Sat, 6 Mar 2004 21:52:59 +0000 Subject: [PATCH] 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 git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/logging/trunk@139022 13f79535-47bb-0310-9956-ffa450edef68 --- .../commons/logging/impl/LogFactoryImpl.java | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/java/org/apache/commons/logging/impl/LogFactoryImpl.java b/src/java/org/apache/commons/logging/impl/LogFactoryImpl.java index 51ac8b0..cae32ea 100644 --- a/src/java/org/apache/commons/logging/impl/LogFactoryImpl.java +++ b/src/java/org/apache/commons/logging/impl/LogFactoryImpl.java @@ -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"; + /** + *

The name of the {@link Log} interface class.

+ */ + 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 + ("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"); + ("Class " + logClassName + " does not implement '" + + LOG_INTERFACE + "'."); } } catch (Throwable t) { throw new LogConfigurationException(t);