[logback-dev] svn commit: r2065 - in logback/trunk/logback-classic/src: main/java/ch/qos/logback/classic test/java/ch/qos/logback/classic

noreply.ceki at qos.ch noreply.ceki at qos.ch
Fri Dec 5 11:00:48 CET 2008


Author: ceki
Date: Fri Dec  5 11:00:48 2008
New Revision: 2065

Modified:
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/Logger.java
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/LoggerTest.java

Log:
Fix LBCLASSIC-91

An NPE would be thrown when setting the level of a logger to null, if the
logger in question had children.


Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/Logger.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/Logger.java	(original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/Logger.java	Fri Dec  5 11:00:48 2008
@@ -163,12 +163,13 @@
     } else {
       effectiveLevelInt = newLevel.levelInt;
     }
+    
     if (childrenList != null) {
       int len = childrenList.size();
       for (int i = 0; i < len; i++) {
         Logger child = (Logger) childrenList.get(i);
         // tell child to handle parent levelInt change
-        child.handleParentLevelChange(newLevel);
+        child.handleParentLevelChange(effectiveLevelInt);
       }
     }
   }
@@ -179,18 +180,18 @@
    * 
    * @param newParentLevel
    */
-  private synchronized void handleParentLevelChange(Level newParentLevel) {
+  private synchronized void handleParentLevelChange(int newParentLevelInt) {
     // changes in the parent levelInt affect children only if their levelInt is
     // null
     if (level == null) {
-      effectiveLevelInt = newParentLevel.levelInt;
+      effectiveLevelInt = newParentLevelInt;
 
       // propagate the parent levelInt change to this logger's children
       if (childrenList != null) {
         int len = childrenList.size();
         for (int i = 0; i < len; i++) {
           Logger child = (Logger) childrenList.get(i);
-          child.handleParentLevelChange(newParentLevel);
+          child.handleParentLevelChange(newParentLevelInt);
         }
       }
     }

Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/LoggerTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/LoggerTest.java	(original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/LoggerTest.java	Fri Dec  5 11:00:48 2008
@@ -189,4 +189,13 @@
     loggerTest.setLevel(null);
     assertEquals(root.getEffectiveLevel(), loggerTest.getEffectiveLevel());
   }
+  
+  @Test
+  public void setLevelToNull_LBCLASSIC_91() {
+    loggerTest.setLevel(Level.DEBUG);
+    lc.getLogger(loggerTest.getName() + ".child");
+    loggerTest.setLevel(null);
+    assertEquals(root.getEffectiveLevel(), loggerTest.getEffectiveLevel());
+  }
+
 }


More information about the logback-dev mailing list