Bläddra i källkod

MAPREDUCE-2249. Check the reflexive property of Counters objects when comparing equality. Contributed by Devaraj K.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1144097 13f79535-47bb-0310-9956-ffa450edef68
Todd Lipcon 14 år sedan
förälder
incheckning
86236dd6c4
2 ändrade filer med 21 tillägg och 6 borttagningar
  1. 3 0
      mapreduce/CHANGES.txt
  2. 18 6
      mapreduce/src/java/org/apache/hadoop/mapred/Counters.java

+ 3 - 0
mapreduce/CHANGES.txt

@@ -180,6 +180,9 @@ Trunk (unreleased changes)
     HADOOP-7106. Reorganize project SVN layout to "unsplit" the projects.
     (todd, nigel)
 
+    MAPREDUCE-2249. Check the reflexive property of Counters objects when
+    comparing equality. (Devaraj K via todd)
+
   OPTIMIZATIONS
 
     MAPREDUCE-2026. Make JobTracker.getJobCounters() and

+ 18 - 6
mapreduce/src/java/org/apache/hadoop/mapred/Counters.java

@@ -271,10 +271,16 @@ public class Counters implements Writable, Iterable<Counters.Group> {
      * Checks for (content) equality of Groups
      */
     @Override
-    public synchronized boolean equals(Object obj) {
+    public boolean equals(Object obj) {
+      if (this == obj) {
+        return true;
+      }
+      if (obj == null || obj.getClass() != getClass()) {
+        return false;
+      }
       boolean isEqual = false;
-      if (obj != null && obj instanceof Group) {
-        Group g = (Group) obj;
+      Group g = (Group) obj;
+      synchronized (this) {
         if (size() == g.size()) {
           isEqual = true;
           for (Map.Entry<String, Counter> entry : subcounters.entrySet()) {
@@ -769,10 +775,16 @@ public class Counters implements Writable, Iterable<Counters.Group> {
   }
 
   @Override
-  public synchronized boolean equals(Object obj) {
+  public boolean equals(Object obj) {
+    if (this == obj) {
+      return true;
+    }
+    if (obj == null || obj.getClass() != getClass()) {
+      return false;
+    }
     boolean isEqual = false;
-    if (obj != null && obj instanceof Counters) {
-      Counters other = (Counters) obj;
+    Counters other = (Counters) obj;
+    synchronized (this) {
       if (size() == other.size()) {
         isEqual = true;
         for (Map.Entry<String, Group> entry : this.counters.entrySet()) {