From 8c0078d1758ad60c685351313c168e509541e914 Mon Sep 17 00:00:00 2001 From: nkeywal Date: Mon, 25 Nov 2013 13:20:51 +0000 Subject: [PATCH] HBASE-10023 Fix/Suppress all the 10 findbug warnings under hbase-common (Liang Xie) git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1545257 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/hadoop/hbase/CellComparator.java | 6 +++--- .../java/org/apache/hadoop/hbase/KeyValue.java | 2 +- .../io/encoding/BufferedDataBlockEncoder.java | 10 ++-------- .../hadoop/hbase/io/hfile/HFileContext.java | 16 +++++----------- .../java/org/apache/hadoop/hbase/util/Bytes.java | 6 ++---- .../apache/hadoop/hbase/util/ChecksumType.java | 2 +- .../hadoop/hbase/util/ConcatenatedLists.java | 3 +++ .../java/org/apache/hadoop/hbase/util/JVM.java | 3 +++ .../org/apache/hadoop/hbase/util/KeyLocker.java | 2 +- 9 files changed, 21 insertions(+), 29 deletions(-) diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/CellComparator.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/CellComparator.java index 2d037846449..2e02ad2c599 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/CellComparator.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/CellComparator.java @@ -82,7 +82,7 @@ public class CellComparator implements Comparator, Serializable{ if (c != 0) return c; //timestamp: later sorts first - c = -Longs.compare(a.getTimestamp(), b.getTimestamp()); + c = Longs.compare(b.getTimestamp(), a.getTimestamp()); if (c != 0) return c; //type @@ -90,7 +90,7 @@ public class CellComparator implements Comparator, Serializable{ if (c != 0) return c; //mvccVersion: later sorts first - return -Longs.compare(a.getMvccVersion(), b.getMvccVersion()); + return Longs.compare(b.getMvccVersion(), a.getMvccVersion()); } @@ -197,7 +197,7 @@ public class CellComparator implements Comparator, Serializable{ if (c != 0) return c; //timestamp: later sorts first - c = -Longs.compare(a.getTimestamp(), b.getTimestamp()); + c = Longs.compare(b.getTimestamp(), a.getTimestamp()); if (c != 0) return c; //type diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java index fd6840361bd..837840393b8 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java @@ -2055,7 +2055,7 @@ public class KeyValue implements Cell, HeapSize, Cloneable { // compare Mvcc Version // Negate this comparison so later edits show up first - return -Longs.compare(left.getMvccVersion(), right.getMvccVersion()); + return Longs.compare(right.getMvccVersion(), left.getMvccVersion()); } public int compareTimestamps(final KeyValue left, final KeyValue right) { diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/BufferedDataBlockEncoder.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/BufferedDataBlockEncoder.java index 8ccab7fd87f..bed388670ac 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/BufferedDataBlockEncoder.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/BufferedDataBlockEncoder.java @@ -156,11 +156,7 @@ abstract class BufferedDataBlockEncoder implements DataBlockEncoder { public BufferedEncodedSeeker(KVComparator comparator, HFileBlockDecodingContext decodingCtx) { this.comparator = comparator; - if (comparator instanceof SamePrefixComparator) { - this.samePrefixComparator = (SamePrefixComparator) comparator; - } else { - this.samePrefixComparator = null; - } + this.samePrefixComparator = comparator; this.decodingCtx = decodingCtx; if (decodingCtx.getHFileContext().isCompressTags()) { try { @@ -468,9 +464,7 @@ abstract class BufferedDataBlockEncoder implements DataBlockEncoder { HFileBlockDefaultEncodingContext encodingCtx = (HFileBlockDefaultEncodingContext) blkEncodingCtx; encodingCtx.prepareEncoding(); - DataOutputStream dataOut = - ((HFileBlockDefaultEncodingContext) encodingCtx) - .getOutputStreamForEncoder(); + DataOutputStream dataOut = encodingCtx.getOutputStreamForEncoder(); if (encodingCtx.getHFileContext().isCompressTags()) { try { TagCompressionContext tagCompressionContext = new TagCompressionContext(LRUDictionary.class); diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileContext.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileContext.java index 1b8f4ee97a0..632c93fed2e 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileContext.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileContext.java @@ -155,16 +155,10 @@ public class HFileContext implements HeapSize, Cloneable { @Override public HFileContext clone() { - HFileContext clonnedCtx = new HFileContext(); - clonnedCtx.usesHBaseChecksum = this.usesHBaseChecksum; - clonnedCtx.includesMvcc = this.includesMvcc; - clonnedCtx.includesTags = this.includesTags; - clonnedCtx.compressAlgo = this.compressAlgo; - clonnedCtx.compressTags = this.compressTags; - clonnedCtx.checksumType = this.checksumType; - clonnedCtx.bytesPerChecksum = this.bytesPerChecksum; - clonnedCtx.blocksize = this.blocksize; - clonnedCtx.encoding = this.encoding; - return clonnedCtx; + try { + return (HFileContext)(super.clone()); + } catch (CloneNotSupportedException e) { + throw new AssertionError(); // Won't happen + } } } diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Bytes.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Bytes.java index a328be96399..a89362ed0ee 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Bytes.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Bytes.java @@ -190,14 +190,12 @@ public class Bytes { /** * Pass this to TreeMaps where byte [] are keys. */ - public static Comparator BYTES_COMPARATOR = - new ByteArrayComparator(); + public final static Comparator BYTES_COMPARATOR = new ByteArrayComparator(); /** * Use comparing byte arrays, byte-by-byte */ - public static RawComparator BYTES_RAWCOMPARATOR = - new ByteArrayComparator(); + public final static RawComparator BYTES_RAWCOMPARATOR = new ByteArrayComparator(); /** * Read byte-array written with a WritableableUtils.vint prefix. diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/ChecksumType.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/ChecksumType.java index 63d3a2e0dfc..e160dac5277 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/ChecksumType.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/ChecksumType.java @@ -49,7 +49,7 @@ public enum ChecksumType { }, CRC32((byte)1) { - private volatile Constructor ctor; + private transient Constructor ctor; @Override public String getName() { diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/ConcatenatedLists.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/ConcatenatedLists.java index 67a0b85c3d7..cf8c191d0c0 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/ConcatenatedLists.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/ConcatenatedLists.java @@ -129,6 +129,9 @@ public class ConcatenatedLists implements Collection { return new Iterator(); } + @edu.umd.cs.findbugs.annotations.SuppressWarnings( + value="URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD", + justification="nextWasCalled is using by StripeStoreFileManager") public class Iterator implements java.util.Iterator { protected int currentComponent = 0; protected int indexWithinComponent = -1; diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/JVM.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/JVM.java index a2dd5ad46fb..647a0ebf206 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/JVM.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/JVM.java @@ -184,6 +184,9 @@ public class JVM { * Workaround to get the current number of process running. Approach is the one described here: * http://stackoverflow.com/questions/54686/how-to-get-a-list-of-current-open-windows-process-with-java */ + @edu.umd.cs.findbugs.annotations.SuppressWarnings( + value="RV_DONT_JUST_NULL_CHECK_READLINE", + justification="used by testing") public int getNumberOfRunningProcess(){ if (!isUnix()){ return 0; diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/KeyLocker.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/KeyLocker.java index 27a7a2cb2ee..e6814997dac 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/KeyLocker.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/KeyLocker.java @@ -117,7 +117,7 @@ public class KeyLocker> { static class KeyLock> extends ReentrantLock { private static final long serialVersionUID = -12432857283423584L; - private final KeyLocker locker; + private final transient KeyLocker locker; private final K lockId; private KeyLock(KeyLocker locker, K lockId) {