From 89c147d46f6bc4f8ca78308b76631ac97a79376b Mon Sep 17 00:00:00 2001 From: Chris Nauroth Date: Fri, 27 Sep 2013 18:32:18 +0000 Subject: [PATCH] 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 --- .../org/apache/hadoop/io/ElasticByteBufferPool.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/ElasticByteBufferPool.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/ElasticByteBufferPool.java index c4b4491ec3a..694fcbebcf6 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/ElasticByteBufferPool.java +++ b/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 buffers =