Repository: logging-log4j2
Updated Branches:
  refs/heads/master 28bb99a7c -> 18c674ab1


[LOG4J2-1064] org.apache.logging.slf4j.Log4jMarker does not implement
org.slf4j.Marker.equals(Object) org.slf4j.Marker.hashCode().

Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/18c674ab
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/18c674ab
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/18c674ab

Branch: refs/heads/master
Commit: 18c674ab19363ae9cbae1d3217c07e1b349dae88
Parents: 28bb99a
Author: ggregory <[email protected]>
Authored: Mon Jun 22 11:53:45 2015 -0700
Committer: ggregory <[email protected]>
Committed: Mon Jun 22 11:53:45 2015 -0700

----------------------------------------------------------------------
 .../org/apache/logging/slf4j/Log4jMarker.java   | 34 ++++++++++++++++--
 .../apache/logging/slf4j/Log4jMarkerTest.java   | 38 ++++++++++++++++++++
 .../org/apache/logging/slf4j/MarkerTest.java    | 19 ++++++++++
 src/changes/changes.xml                         |  3 ++
 4 files changed, 92 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/18c674ab/log4j-slf4j-impl/src/main/java/org/apache/logging/slf4j/Log4jMarker.java
----------------------------------------------------------------------
diff --git 
a/log4j-slf4j-impl/src/main/java/org/apache/logging/slf4j/Log4jMarker.java 
b/log4j-slf4j-impl/src/main/java/org/apache/logging/slf4j/Log4jMarker.java
index a146ee9..69dbe5d 100644
--- a/log4j-slf4j-impl/src/main/java/org/apache/logging/slf4j/Log4jMarker.java
+++ b/log4j-slf4j-impl/src/main/java/org/apache/logging/slf4j/Log4jMarker.java
@@ -66,6 +66,28 @@ public class Log4jMarker implements Marker {
                return s != null ? this.marker.isInstanceOf(s) : false;
        }
 
+    @Override
+       public boolean equals(Object obj) {
+               if (this == obj) {
+                       return true;
+               }
+               if (obj == null) {
+                       return false;
+               }
+               if (!(obj instanceof Log4jMarker)) {
+                       return false;
+               }
+               Log4jMarker other = (Log4jMarker) obj;
+               if (marker == null) {
+                       if (other.marker != null) {
+                               return false;
+                       }
+               } else if (!marker.equals(other.marker)) {
+                       return false;
+               }
+               return true;
+       }
+
     public org.apache.logging.log4j.Marker getLog4jMarker() {
         return marker;
     }
@@ -81,11 +103,19 @@ public class Log4jMarker implements Marker {
     }
 
     @Override
+       public int hashCode() {
+               final int prime = 31;
+               int result = 1;
+               result = prime * result + ((marker == null) ? 0 : 
marker.hashCode());
+               return result;
+       }
+
+    @Override
     public boolean hasReferences() {
         return marker.hasParents();
     }
 
-    @Override
+       @Override
     public Iterator<Marker> iterator() {
         org.apache.logging.log4j.Marker[] log4jParents = 
this.marker.getParents();
         final List<Marker> parents = new ArrayList<>(log4jParents.length);
@@ -95,7 +125,7 @@ public class Log4jMarker implements Marker {
         return parents.iterator();
     }
 
-    @Override
+       @Override
        public boolean remove(final Marker marker) {
                return marker != null ? 
this.marker.remove(MarkerManager.getMarker(marker.getName())) : false;
        }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/18c674ab/log4j-slf4j-impl/src/test/java/org/apache/logging/slf4j/Log4jMarkerTest.java
----------------------------------------------------------------------
diff --git 
a/log4j-slf4j-impl/src/test/java/org/apache/logging/slf4j/Log4jMarkerTest.java 
b/log4j-slf4j-impl/src/test/java/org/apache/logging/slf4j/Log4jMarkerTest.java
new file mode 100644
index 0000000..9d034ae
--- /dev/null
+++ 
b/log4j-slf4j-impl/src/test/java/org/apache/logging/slf4j/Log4jMarkerTest.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.slf4j;
+
+import org.apache.logging.log4j.Marker;
+import org.apache.logging.log4j.MarkerManager;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class Log4jMarkerTest {
+
+       @Test
+       public void testEquals() {
+               Marker markerA = 
MarkerManager.getMarker(Log4jMarkerTest.class.getName() + "-A");
+               Marker markerB = 
MarkerManager.getMarker(Log4jMarkerTest.class.getName() + "-B");
+               Log4jMarker marker1 = new Log4jMarker(markerA);
+               Log4jMarker marker2 = new Log4jMarker(markerA);
+               Log4jMarker marker3 = new Log4jMarker(markerB);
+               Assert.assertEquals(marker1, marker2);
+               Assert.assertNotEquals(marker1, null);
+               Assert.assertNotEquals(null, marker1);
+               Assert.assertNotEquals(marker1, marker3);
+       }
+}

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/18c674ab/log4j-slf4j-impl/src/test/java/org/apache/logging/slf4j/MarkerTest.java
----------------------------------------------------------------------
diff --git 
a/log4j-slf4j-impl/src/test/java/org/apache/logging/slf4j/MarkerTest.java 
b/log4j-slf4j-impl/src/test/java/org/apache/logging/slf4j/MarkerTest.java
index eb8fdd2..50743a6 100644
--- a/log4j-slf4j-impl/src/test/java/org/apache/logging/slf4j/MarkerTest.java
+++ b/log4j-slf4j-impl/src/test/java/org/apache/logging/slf4j/MarkerTest.java
@@ -99,6 +99,25 @@ public class MarkerTest {
        }
 
        @Test
+       public void testEquals() {
+               String childMarkerName = CHILD_MAKER_NAME + "-ASM";
+               String parentMakerName = PARENT_MARKER_NAME + "-ASM";
+               final org.slf4j.Marker slf4jMarker = 
org.slf4j.MarkerFactory.getMarker(childMarkerName);
+               final org.slf4j.Marker slf4jMarker2 = 
org.slf4j.MarkerFactory.getMarker(childMarkerName);
+               final org.slf4j.Marker slf4jParent = 
org.slf4j.MarkerFactory.getMarker(parentMakerName);
+               slf4jMarker.add(slf4jParent);
+               final Marker log4jParent = 
MarkerManager.getMarker(parentMakerName);
+               final Marker log4jMarker = 
MarkerManager.getMarker(childMarkerName);
+               final Marker log4jMarker2 = 
MarkerManager.getMarker(childMarkerName);
+               assertEquals(log4jParent, log4jParent);
+               assertEquals(log4jMarker, log4jMarker);
+               assertEquals(log4jMarker, log4jMarker2);
+               assertEquals(slf4jMarker, slf4jMarker2);
+               assertNotEquals(log4jParent, log4jMarker);
+               assertNotEquals(log4jMarker, log4jParent);
+       }
+
+       @Test
        public void testContainsNullMarker() {
                String childMarkerName = CHILD_MAKER_NAME + "-CM";
                String parentMakerName = PARENT_MARKER_NAME + "-CM";

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/18c674ab/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index fb305c6..88a44d4 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -99,6 +99,9 @@
       <action issue="LOG4J2-1062" dev="ggregory" type="fix">
         Log4jMarker#add(Marker) does not respect org.slf4j.Marker contract.
       </action>            
+      <action issue="LOG4J2-1064" dev="ggregory" type="fix">
+        org.apache.logging.slf4j.Log4jMarker does not implement 
org.slf4j.Marker.equals(Object) org.slf4j.Marker.hashCode().
+      </action>            
       <action issue="LOG4J2-1065" dev="ggregory" type="update">
         Define org.apache.logging.log4j.Marker.equals(Object) and 
org.apache.logging.log4j.Marker.hashCode().
       </action>

Reply via email to