瀏覽代碼

HDFS-5266. Addendum for addressing Findbugs warnings for lack of hashCode method and lack of null check in equals. Contributed by Chris Nauroth.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/HDFS-4949@1527023 13f79535-47bb-0310-9956-ffa450edef68
Chris Nauroth 11 年之前
父節點
當前提交
89c147d46f

+ 12 - 0
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/ElasticByteBufferPool.java

@@ -18,6 +18,7 @@
 package org.apache.hadoop.io;
 
 import com.google.common.collect.ComparisonChain;
+import org.apache.commons.lang.builder.HashCodeBuilder;
 
 import java.nio.ByteBuffer;
 import java.util.Map;
@@ -55,6 +56,9 @@ public final class ElasticByteBufferPool implements ByteBufferPool {
 
     @Override
     public boolean equals(Object rhs) {
+      if (rhs == null) {
+        return false;
+      }
       try {
         Key o = (Key)rhs;
         return (compareTo(o) == 0);
@@ -62,6 +66,14 @@ public final class ElasticByteBufferPool implements ByteBufferPool {
         return false;
       }
     }
+
+    @Override
+    public int hashCode() {
+      return new HashCodeBuilder().
+          append(capacity).
+          append(insertionTime).
+          toHashCode();
+    }
   }
 
   private final TreeMap<Key, ByteBuffer> buffers =