[slf4j-dev] svn commit: r1093 - in slf4j/trunk/slf4j-api/src: main/java/org/slf4j/helpers test/java/org/slf4j

ceki at slf4j.org ceki at slf4j.org
Sat Aug 2 22:30:33 CEST 2008


Author: ceki
Date: Sat Aug  2 22:30:32 2008
New Revision: 1093

Modified:
   slf4j/trunk/slf4j-api/src/main/java/org/slf4j/helpers/BasicMarker.java
   slf4j/trunk/slf4j-api/src/test/java/org/slf4j/BasicMarkerTest.java

Log:
As Joern Huxhorn observed in bug 76, markers are usually unique by
name but under certain circumstances, notably deserialization, there
might be multiple markers with the same name. Consequently, the
BasicMarker.remove(Marker) and BasicMarker.contains(Marker) methods
have been modified to use equals() instead of ==.

Modified: slf4j/trunk/slf4j-api/src/main/java/org/slf4j/helpers/BasicMarker.java
==============================================================================
--- slf4j/trunk/slf4j-api/src/main/java/org/slf4j/helpers/BasicMarker.java	(original)
+++ slf4j/trunk/slf4j-api/src/main/java/org/slf4j/helpers/BasicMarker.java	Sat Aug  2 22:30:32 2008
@@ -32,15 +32,7 @@
 import org.slf4j.Marker;
 
 /**
- * An almost trivial implementation of the {@link Marker} interface.
- * 
- * <p>
- * <code>BasicMarker</code> lets users specify marker information. However, it
- * does not offer any useful operations on that information.
- * 
- * <p>
- * Simple logging systems which ignore marker data, just return instances of
- * this class in order to conform to the SLF4J API.
+ * An simple implementation of the {@link Marker} interface.
  * 
  * @author Ceki G&uuml;lc&uuml;
  * @author Joern Huxhorn
@@ -106,7 +98,7 @@
     int size = children.size();
     for (int i = 0; i < size; i++) {
       Marker m = (Marker) children.get(i);
-      if (m == markerToRemove) {
+      if (markerToRemove.equals(m)) {
         children.remove(i);
         return true;
       }
@@ -120,7 +112,7 @@
       throw new IllegalArgumentException("Other cannot be null");
     }
 
-    if (this == other) {
+    if (this.equals(other)) {
       return true;
     }
 

Modified: slf4j/trunk/slf4j-api/src/test/java/org/slf4j/BasicMarkerTest.java
==============================================================================
--- slf4j/trunk/slf4j-api/src/test/java/org/slf4j/BasicMarkerTest.java	(original)
+++ slf4j/trunk/slf4j-api/src/test/java/org/slf4j/BasicMarkerTest.java	Sat Aug  2 22:30:32 2008
@@ -175,4 +175,22 @@
     assertFalse(parent.contains(NOT_CONTAINED_MARKER_STR));
   }
 
+  public void testHomonyms() {
+    final String diffPrefix = "homonym"+diff;
+    final String PARENT_NAME=diffPrefix+PARENT_MARKER_STR;
+    final String CHILD_NAME=diffPrefix+CHILD_MARKER_STR;
+    Marker parent = factory.getMarker(PARENT_NAME);
+    Marker child = factory.getMarker(CHILD_NAME);
+    parent.add(child);
+   
+    IMarkerFactory otherFactory = new BasicMarkerFactory();
+    Marker otherParent = otherFactory.getMarker(PARENT_NAME);
+    Marker otherChild = otherFactory.getMarker(CHILD_NAME);
+    
+    assertTrue(parent.contains(otherParent));
+    assertTrue(parent.contains(otherChild));
+    
+    assertTrue(parent.remove(otherChild));
+  }
+  
 }



More information about the slf4j-dev mailing list