rsitze 2002/10/17 16:00:04
Modified: logging/src/test/org/apache/commons/logging
AbstractLogTest.java
logging/src/java/org/apache/commons/logging LogFactory.java
Log:
Bugzilla Defect 10825 [thanks for the patch & the education!]
Added real text & exceptions to tests.. it's harder to read :-(
Revision Changes Path
1.3 +12 -12
jakarta-commons/logging/src/test/org/apache/commons/logging/AbstractLogTest.java
Index: AbstractLogTest.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/logging/src/test/org/apache/commons/logging/AbstractLogTest.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- AbstractLogTest.java 11 Oct 2002 05:02:59 -0000 1.2
+++ AbstractLogTest.java 17 Oct 2002 23:00:04 -0000 1.3
@@ -86,29 +86,29 @@
assertNotNull(log);
- log.debug(null);
+ log.debug("debug statement");
- log.debug(null, null);
+ log.debug("debug statement w/ null exception", new RuntimeException());
- log.error(null);
+ log.error("error statement");
- log.error(null, null);
+ log.error("error statement w/ null exception", new RuntimeException());
- log.fatal(null);
+ log.fatal("fatal statement");
- log.fatal(null, null);
+ log.fatal("fatal statement w/ null exception", new RuntimeException());
- log.info(null);
+ log.info("info statement");
- log.info(null, null);
+ log.info("info statement w/ null exception", new RuntimeException());
- log.trace(null);
+ log.trace("trace statement");
- log.trace(null, null);
+ log.trace("trace statement w/ null exception", new RuntimeException());
- log.warn(null);
+ log.warn("warn statement");
- log.warn(null, null);
+ log.warn("warn statement w/ null exception", new RuntimeException());
}
}
1.13 +27 -22
jakarta-commons/logging/src/java/org/apache/commons/logging/LogFactory.java
Index: LogFactory.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/logging/src/java/org/apache/commons/logging/LogFactory.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- LogFactory.java 30 Aug 2002 03:23:34 -0000 1.12
+++ LogFactory.java 17 Oct 2002 23:00:04 -0000 1.13
@@ -534,29 +534,34 @@
{
try {
- if (classLoader == null)
- classLoader = LogFactory.class.getClassLoader();
-
Class clazz = null;
- try {
- // first the thread class loader
- clazz = classLoader.loadClass(factoryClass);
- } catch (ClassNotFoundException ex) {
- // if this failed (i.e. no implementation is
- // found in the webapp), try the caller's loader
- // if we haven't already...
- if (classLoader != LogFactory.class.getClassLoader()) {
- classLoader = LogFactory.class.getClassLoader();
- clazz = classLoader.loadClass(factoryClass);
+ if (classLoader != null) {
+ try {
+ // first the given class loader param (thread class loader)
+ return
(LogFactory)classLoader.loadClass(factoryClass).newInstance();
+ } catch (ClassNotFoundException ex) {
+ if (classLoader == LogFactory.class.getClassLoader()) {
+ // Nothing more to try, onwards.
+ throw ex;
+ }
+ // ignore exception, continue
}
}
-
- LogFactory factory = (LogFactory)clazz.newInstance();
-
- return factory;
+
+ /* 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) {
throw new LogConfigurationException(e);
}
-
}
}
--
To unsubscribe, e-mail: <mailto:commons-dev-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@;jakarta.apache.org>