[slf4j-dev] svn commit: r1019 - in slf4j/trunk: slf4j-api/src/main/java/org/slf4j slf4j-api/src/main/java/org/slf4j/helpers slf4j-api/src/test/java/org/slf4j/helpers slf4j-log4j12/src/test/java/org/slf4j slf4j-site/src/site/pages

ceki at slf4j.org ceki at slf4j.org
Tue May 27 22:49:17 CEST 2008


Author: ceki
Date: Tue May 27 22:49:17 2008
New Revision: 1019

Modified:
   slf4j/trunk/slf4j-api/src/main/java/org/slf4j/Logger.java
   slf4j/trunk/slf4j-api/src/main/java/org/slf4j/helpers/MessageFormatter.java
   slf4j/trunk/slf4j-api/src/test/java/org/slf4j/helpers/MessageFormatterTest.java
   slf4j/trunk/slf4j-log4j12/src/test/java/org/slf4j/InvocationTest.java
   slf4j/trunk/slf4j-site/src/site/pages/news.html

Log:
- fixed bug 78.  If the argument array passed
  to a Logger printing method (debug, info, etc.) was null, a NullPointerException
   was thrown. With the correction, the messagePattern is returned as is, without parameter
  substitution.
- updated javadocs

Modified: slf4j/trunk/slf4j-api/src/main/java/org/slf4j/Logger.java
==============================================================================
--- slf4j/trunk/slf4j-api/src/main/java/org/slf4j/Logger.java	(original)
+++ slf4j/trunk/slf4j-api/src/main/java/org/slf4j/Logger.java	Tue May 27 22:49:17 2008
@@ -26,8 +26,9 @@
 package org.slf4j;
 
 /**
- * The main user interface to logging. It is expected that logging
- * takes place through concrete implementations of this interface.
+ * The org.slf4j.Logger interface is the main user entry point of SLF4J API. 
+ * It is expected that logging takes place through concrete implementations 
+ * of this interface.
  *
  * <h3>Typical usage pattern:</h3>
  * <pre>

Modified: slf4j/trunk/slf4j-api/src/main/java/org/slf4j/helpers/MessageFormatter.java
==============================================================================
--- slf4j/trunk/slf4j-api/src/main/java/org/slf4j/helpers/MessageFormatter.java	(original)
+++ slf4j/trunk/slf4j-api/src/main/java/org/slf4j/helpers/MessageFormatter.java	Tue May 27 22:49:17 2008
@@ -131,6 +131,10 @@
     int len = messagePattern.length();
     int j = messagePattern.indexOf(DELIM_START);
 
+    if(argArray == null) {
+      return messagePattern;
+    }
+    
     StringBuffer sbuf = new StringBuffer(messagePattern.length() + 50);
 
     for (int L = 0; L < argArray.length; L++) {
@@ -175,7 +179,7 @@
         }
       }
     }
-    // append the characters following the second {} pair.
+    // append the characters following the last {} pair.
     sbuf.append(messagePattern.substring(i, messagePattern.length()));
     return sbuf.toString();
   }

Modified: slf4j/trunk/slf4j-api/src/test/java/org/slf4j/helpers/MessageFormatterTest.java
==============================================================================
--- slf4j/trunk/slf4j-api/src/test/java/org/slf4j/helpers/MessageFormatterTest.java	(original)
+++ slf4j/trunk/slf4j-api/src/test/java/org/slf4j/helpers/MessageFormatterTest.java	Tue May 27 22:49:17 2008
@@ -151,6 +151,28 @@
     assertEquals("Value {} is smaller than 1", result);    
   }
   
+  public void testNullArray() {
+    String result;
+    
+    String msg0 = "msg0";
+    String msg1 = "msg1 {}";
+    String msg2 = "msg2 {} {}";
+    String msg3 = "msg3 {} {} {}";
+
+    Object[] args = null;
+
+    result = MessageFormatter.arrayFormat(msg0, args);
+    assertEquals(msg0, result);
+    
+    result = MessageFormatter.arrayFormat(msg1, args);
+    assertEquals(msg1, result);
+    
+    result = MessageFormatter.arrayFormat(msg2, args);
+    assertEquals(msg2, result);
+    
+    result = MessageFormatter.arrayFormat(msg3, args);
+    assertEquals(msg3, result);
+  }
   public void testArray() {
     String result;
 

Modified: slf4j/trunk/slf4j-log4j12/src/test/java/org/slf4j/InvocationTest.java
==============================================================================
--- slf4j/trunk/slf4j-log4j12/src/test/java/org/slf4j/InvocationTest.java	(original)
+++ slf4j/trunk/slf4j-log4j12/src/test/java/org/slf4j/InvocationTest.java	Tue May 27 22:49:17 2008
@@ -33,6 +33,8 @@
 
 package org.slf4j;
 
+import org.apache.log4j.spi.LoggingEvent;
+
 import junit.framework.TestCase;
 
 /**
@@ -108,7 +110,19 @@
     logger.error(null, e);
     assertEquals(8, listAppender.list.size());
   }
-
+  
+  // http://bugzilla.slf4j.org/show_bug.cgi?id=78
+  public void testNullParameter_BUG78() {
+    Logger logger = LoggerFactory.getLogger("testNullParameter_BUG78");
+    String[] parameters = null;
+    String msg = "hello {}";
+    
+    logger.debug(msg, parameters);
+    assertEquals(1, listAppender.list.size());
+    LoggingEvent e = (LoggingEvent) listAppender.list.get(0);
+    assertEquals(msg, e.getMessage());
+  }
+  
   public void testMarker() {
     Logger logger = LoggerFactory.getLogger("testMarker");
     Marker blue = MarkerFactory.getMarker("BLUE");

Modified: slf4j/trunk/slf4j-site/src/site/pages/news.html
==============================================================================
--- slf4j/trunk/slf4j-site/src/site/pages/news.html	(original)
+++ slf4j/trunk/slf4j-site/src/site/pages/news.html	Tue May 27 22:49:17 2008
@@ -42,6 +42,15 @@
   </p>
 
   
+  <p>Fixed <a href="http://bugzilla.slf4j.org/show_bug.cgi?id=78">bug
+  78</a> reported by Venu Thachappilly. If the argument array passed
+  to a Logger printing method (debug, info, etc.) was null, a
+  <code>NullPointerException</code> was thrown. With the correction,
+  the messagePattern is returned as is, without parameter
+  substitution.
+  </p>
+
+
   <p>Added the <code>getCopyOfContextMap</code> method to the
   <code>MDCAdapter</code> and <code>org.sf4j.MDC</code> classes. This
   was requested in <a



More information about the slf4j-dev mailing list