logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rpo...@apache.org
Subject svn commit: r1617497 - in /logging/log4j/log4j2/trunk/log4j-api/src: main/java/org/apache/logging/log4j/message/ObjectMessage.java test/java/org/apache/logging/log4j/message/ObjectMessageTest.java
Date Tue, 12 Aug 2014 14:52:48 GMT
Author: rpopma
Date: Tue Aug 12 14:52:47 2014
New Revision: 1617497

URL: http://svn.apache.org/r1617497
Log:
LOG4J2-763: change ObjectMessage.equals() to account for the fact that the parameter may have
been converted to a String during serialization

Modified:
    logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/message/ObjectMessage.java
    logging/log4j/log4j2/trunk/log4j-api/src/test/java/org/apache/logging/log4j/message/ObjectMessageTest.java

Modified: logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/message/ObjectMessage.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/message/ObjectMessage.java?rev=1617497&r1=1617496&r2=1617497&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/message/ObjectMessage.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/message/ObjectMessage.java
Tue Aug 12 14:52:47 2014
@@ -83,7 +83,11 @@ public class ObjectMessage implements Me
         }
 
         final ObjectMessage that = (ObjectMessage) o;
-        return obj == null ? that.obj == null : obj.equals(that.obj);
+        return obj == null ? that.obj == null : equalObjectsOrStrings(obj, that.obj);
+    }
+    
+    private boolean equalObjectsOrStrings(Object left, Object right) {
+        return left.equals(right) || String.valueOf(left).equals(String.valueOf(right));
     }
 
     @Override

Modified: logging/log4j/log4j2/trunk/log4j-api/src/test/java/org/apache/logging/log4j/message/ObjectMessageTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-api/src/test/java/org/apache/logging/log4j/message/ObjectMessageTest.java?rev=1617497&r1=1617496&r2=1617497&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-api/src/test/java/org/apache/logging/log4j/message/ObjectMessageTest.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-api/src/test/java/org/apache/logging/log4j/message/ObjectMessageTest.java
Tue Aug 12 14:52:47 2014
@@ -20,7 +20,6 @@ import java.io.Serializable;
 import java.math.BigDecimal;
 
 import org.apache.log4j.util.SerialUtil;
-import org.junit.Ignore;
 import org.junit.Test;
 
 import static org.junit.Assert.*;
@@ -77,16 +76,6 @@ public class ObjectMessageTest {
     }
     
     @Test
-    public void testDeserializeNonSerializableParamNotEqualIfToStringDiffers() {
-        ObjectMessageTest nonSerializable = new ObjectMessageTest();
-        assertFalse(nonSerializable instanceof Serializable);
-        ObjectMessage msg = new ObjectMessage(nonSerializable);
-        ObjectMessage other = SerialUtil.deserialize(SerialUtil.serialize(msg));
-        assertNotEquals("Expected different: toString is different", msg, other);
-    }
-    
-    @Ignore
-    @Test
     public void testDeserializeNonSerializableParamEqualIfToStringSame() {
         class NonSerializable {
             public boolean equals(Object other) {
@@ -98,8 +87,7 @@ public class ObjectMessageTest {
         ObjectMessage msg = new ObjectMessage(nonSerializable);
         ObjectMessage other = SerialUtil.deserialize(SerialUtil.serialize(msg));
 
-// TODO this fails: msg.obj.equals(other.obj) is false...
-// TODO ObjectMessage.equals() implementation does not match the serialization mechanism
         assertEquals(msg, other);
+        assertEquals(other, msg);
     }
 }



Mime
View raw message