logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgo...@apache.org
Subject svn commit: r1364404 - in /logging/log4j/log4j2/trunk/api/src: main/java/org/apache/logging/log4j/message/ObjectMessage.java test/java/org/apache/logging/log4j/message/ObjectMessageTest.java
Date Sun, 22 Jul 2012 19:33:44 GMT
Author: rgoers
Date: Sun Jul 22 19:33:43 2012
New Revision: 1364404

URL: http://svn.apache.org/viewvc?rev=1364404&view=rev
Log:
Eliminate NullPointerException if a null value is passed to the ObjectMessage constructor.

Added:
    logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/message/ObjectMessageTest.java
      - copied, changed from r1361607, logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/message/ParameterizedMessageTest.java
Modified:
    logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/message/ObjectMessage.java

Modified: logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/message/ObjectMessage.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/message/ObjectMessage.java?rev=1364404&r1=1364403&r2=1364404&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/message/ObjectMessage.java
(original)
+++ logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/message/ObjectMessage.java
Sun Jul 22 19:33:43 2012
@@ -35,6 +35,9 @@ public class ObjectMessage implements Me
      * @param obj The Object to format.
      */
     public ObjectMessage(Object obj) {
+        if (obj == null) {
+            obj = "null";
+        }
         this.obj = obj;
     }
 

Copied: logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/message/ObjectMessageTest.java
(from r1361607, logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/message/ParameterizedMessageTest.java)
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/message/ObjectMessageTest.java?p2=logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/message/ObjectMessageTest.java&p1=logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/message/ParameterizedMessageTest.java&r1=1361607&r2=1364404&rev=1364404&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/message/ParameterizedMessageTest.java
(original)
+++ logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/message/ObjectMessageTest.java
Sun Jul 22 19:33:43 2012
@@ -19,24 +19,24 @@ package org.apache.logging.log4j.message
 import org.junit.Test;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
 
 /**
  *
  */
-public class ParameterizedMessageTest {
+public class ObjectMessageTest {
 
     @Test
-    public void testNoArgs() {
+    public void testNull() {
+        ObjectMessage msg = new ObjectMessage(null);
+        String result = msg.getFormattedMessage();
+        assertEquals("null", result);
+    }
+
+    @Test
+    public void testNotNull() {
         String testMsg = "Test message {}";
-        ParameterizedMessage msg = new ParameterizedMessage(testMsg, null);
+        ObjectMessage msg = new ObjectMessage(testMsg);
         String result = msg.getFormattedMessage();
         assertEquals(testMsg, result);
-        Object[] array = null;
-        msg = new ParameterizedMessage(testMsg, array, null);
-        result = msg.getFormattedMessage();
-        assertEquals(testMsg, result);
     }
 }



Mime
View raw message