From d6dfbd01eb87fe9bdef649a40ae7e88d0287776b Mon Sep 17 00:00:00 2001 From: Simon Kitching Date: Wed, 1 Mar 2006 03:11:41 +0000 Subject: [PATCH] * Fix minor syntax error in previous checkin (oops). * Improve error message when custom LogFactory class cannot be instantiated due to class cast issues. git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/logging/trunk@381886 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/commons/logging/LogFactory.java | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/java/org/apache/commons/logging/LogFactory.java b/src/java/org/apache/commons/logging/LogFactory.java index 41b6555..58c54c3 100644 --- a/src/java/org/apache/commons/logging/LogFactory.java +++ b/src/java/org/apache/commons/logging/LogFactory.java @@ -465,7 +465,7 @@ public abstract class LogFactory { + "]. Trying alternative implementations..."); } ; // ignore - } catch(Exception e) { + } catch(RuntimeException e) { // This is not consistent with the behaviour when a bad LogFactory class is // specified in a services file. // @@ -1096,15 +1096,23 @@ public abstract class LogFactory { // ignore exception, continue } catch(ClassCastException e) { if (classLoader == thisClassLoader) { - // This cast exception is not due to classloader issues; - // the specified class *really* doesn't extend the - // required LogFactory base class. + // There's no point in falling through to the code below that + // tries again with thisClassLoader, because we've just tried + // loading with that loader (not the TCCL). Just throw an + // appropriate exception here. + + String msg = + "Class '" + factoryClass + "' cannot be converted to '" + + LogFactory.class.getName() + "'." + + " Perhaps you have multiple copies of LogFactory in " + + " the classpath?"; + if (isDiagnosticsEnabled()) { - logDiagnostic( - "Class '" + factoryClass + "' really does not extend '" - + LogFactory.class.getName() + "'"); + logDiagnostic(msg); } - throw e; + + ClassCastException ex = new ClassCastException(msg); + throw ex; } // Ignore exception, continue. Presumably the classloader was the