hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject [3/3] hbase git commit: HBASE-15087 Fix hbase-common findbugs complaints
Date Fri, 15 Jan 2016 01:21:57 GMT
HBASE-15087 Fix hbase-common findbugs complaints


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/ab0651ed
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/ab0651ed
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/ab0651ed

Branch: refs/heads/branch-1.2
Commit: ab0651ed2bde277512f0ba869858fc77ebada92c
Parents: 930f68c
Author: stack <stack@apache.org>
Authored: Thu Jan 14 17:18:16 2016 -0800
Committer: stack <stack@apache.org>
Committed: Thu Jan 14 17:18:40 2016 -0800

----------------------------------------------------------------------
 .../JitterScheduledThreadPoolExecutorImpl.java  | 14 +++++++++++-
 .../org/apache/hadoop/hbase/ProcedureInfo.java  |  4 +++-
 .../hadoop/hbase/trace/SpanReceiverHost.java    |  3 ++-
 .../hadoop/hbase/types/CopyOnWriteArrayMap.java | 10 ++++++++-
 .../hadoop/hbase/util/ByteBufferUtils.java      |  1 +
 .../java/org/apache/hadoop/hbase/util/DNS.java  |  4 +++-
 .../hadoop/hbase/util/DynamicClassLoader.java   |  4 +++-
 .../apache/hadoop/hbase/util/PrettyPrinter.java |  2 ++
 .../org/apache/hadoop/hbase/util/Threads.java   | 23 ++++++++++----------
 .../apache/hadoop/hbase/util/UnsafeAccess.java  |  4 +++-
 10 files changed, 50 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/ab0651ed/hbase-common/src/main/java/org/apache/hadoop/hbase/JitterScheduledThreadPoolExecutorImpl.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/JitterScheduledThreadPoolExecutorImpl.java
b/hbase-common/src/main/java/org/apache/hadoop/hbase/JitterScheduledThreadPoolExecutorImpl.java
index 7e7239e..c330fa7 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/JitterScheduledThreadPoolExecutorImpl.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/JitterScheduledThreadPoolExecutorImpl.java
@@ -93,6 +93,19 @@ public class JitterScheduledThreadPoolExecutorImpl extends ScheduledThreadPoolEx
     }
 
     @Override
+    public boolean equals(Object obj) {
+      if (obj == this) {
+        return true;
+      }
+      return obj instanceof Delayed? compareTo((Delayed)obj) == 0: false;
+    }
+
+    @Override
+    public int hashCode() {
+      return this.wrapped.hashCode();
+    }
+
+    @Override
     public void run() {
       wrapped.run();
     }
@@ -123,5 +136,4 @@ public class JitterScheduledThreadPoolExecutorImpl extends ScheduledThreadPoolEx
       return wrapped.get(timeout, unit);
     }
   }
-
 }

http://git-wip-us.apache.org/repos/asf/hbase/blob/ab0651ed/hbase-common/src/main/java/org/apache/hadoop/hbase/ProcedureInfo.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/ProcedureInfo.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/ProcedureInfo.java
index 0cd4103..11264cd 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/ProcedureInfo.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/ProcedureInfo.java
@@ -35,7 +35,7 @@ import org.apache.hadoop.hbase.util.NonceKey;
  */
 @InterfaceAudience.Public
 @InterfaceStability.Evolving
-public class ProcedureInfo {
+public class ProcedureInfo implements Cloneable {
   private final long procId;
   private final String procName;
   private final String procOwner;
@@ -72,6 +72,8 @@ public class ProcedureInfo {
     this.result = result;
   }
 
+  @edu.umd.cs.findbugs.annotations.SuppressWarnings(value="CN_IDIOM_NO_SUPER_CALL",
+      justification="Intentional; calling super class clone doesn't make sense here.")
   public ProcedureInfo clone() {
     return new ProcedureInfo(
       procId, procName, procOwner, procState, parentId, exception, lastUpdate, startTime,
result);

http://git-wip-us.apache.org/repos/asf/hbase/blob/ab0651ed/hbase-common/src/main/java/org/apache/hadoop/hbase/trace/SpanReceiverHost.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/trace/SpanReceiverHost.java
b/hbase-common/src/main/java/org/apache/hadoop/hbase/trace/SpanReceiverHost.java
index b90d191..2d9c398 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/trace/SpanReceiverHost.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/trace/SpanReceiverHost.java
@@ -42,10 +42,11 @@ public class SpanReceiverHost {
   private Configuration conf;
   private boolean closed = false;
 
+  @edu.umd.cs.findbugs.annotations.SuppressWarnings(value="SE_BAD_FIELD")
   private static enum SingletonHolder {
     INSTANCE;
     Object lock = new Object();
-    SpanReceiverHost host = null;
+    SpanReceiverHost host = null; // FindBugs: SE_BAD_FIELD
   }
 
   public static SpanReceiverHost getInstance(Configuration conf) {

http://git-wip-us.apache.org/repos/asf/hbase/blob/ab0651ed/hbase-common/src/main/java/org/apache/hadoop/hbase/types/CopyOnWriteArrayMap.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/types/CopyOnWriteArrayMap.java
b/hbase-common/src/main/java/org/apache/hadoop/hbase/types/CopyOnWriteArrayMap.java
index 41056b2..8de39ae 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/types/CopyOnWriteArrayMap.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/types/CopyOnWriteArrayMap.java
@@ -27,6 +27,7 @@ import java.util.Comparator;
 import java.util.Iterator;
 import java.util.Map;
 import java.util.NavigableSet;
+import java.util.NoSuchElementException;
 import java.util.Set;
 import java.util.SortedSet;
 import java.util.concurrent.ConcurrentNavigableMap;
@@ -693,8 +694,10 @@ public class CopyOnWriteArrayMap<K, V> extends AbstractMap<K,
V>
     }
 
     @Override
+    @edu.umd.cs.findbugs.annotations.SuppressWarnings(value="EQ_ALWAYS_FALSE",
+      justification="Intentional")
     public boolean equals(Object o) {
-      return false;
+      return false; // FindBugs: Causes EQ_ALWAYS_FALSE. Suppressed.
     }
 
     @Override
@@ -771,7 +774,12 @@ public class CopyOnWriteArrayMap<K, V> extends AbstractMap<K,
V>
     }
 
     @Override
+    @edu.umd.cs.findbugs.annotations.SuppressWarnings(value="IT_NO_SUCH_ELEMENT",
+      justification="Intentional")
     public Entry<K, V> next() {
+      if (!hasNext()) {
+        throw new NoSuchElementException();
+      }
       return holder.entries[index++];
     }
 

http://git-wip-us.apache.org/repos/asf/hbase/blob/ab0651ed/hbase-common/src/main/java/org/apache/hadoop/hbase/util/ByteBufferUtils.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/ByteBufferUtils.java
b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/ByteBufferUtils.java
index 6f348bc..ef3d368 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/ByteBufferUtils.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/ByteBufferUtils.java
@@ -32,6 +32,7 @@ import org.apache.hadoop.io.WritableUtils;
  * Utility functions for working with byte buffers, such as reading/writing
  * variable-length long numbers.
  */
+@SuppressWarnings("restriction")
 @InterfaceAudience.Public
 @InterfaceStability.Evolving
 public final class ByteBufferUtils {

http://git-wip-us.apache.org/repos/asf/hbase/blob/ab0651ed/hbase-common/src/main/java/org/apache/hadoop/hbase/util/DNS.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/DNS.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/DNS.java
index d105a34..4b9e87f 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/DNS.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/DNS.java
@@ -25,6 +25,8 @@ import org.apache.hadoop.hbase.classification.InterfaceAudience;
  * Wrapper around Hadoop's DNS class to hide reflection.
  */
 @InterfaceAudience.Private
+@edu.umd.cs.findbugs.annotations.SuppressWarnings(value="REC_CATCH_EXCEPTION",
+  justification="If exception, presume HAS_NEW_DNS_GET_DEFAULT_HOST_API false")
 public final class DNS {
   private static boolean HAS_NEW_DNS_GET_DEFAULT_HOST_API;
   private static Method GET_DEFAULT_HOST_METHOD;
@@ -35,7 +37,7 @@ public final class DNS {
           .getMethod("getDefaultHost", String.class, String.class, boolean.class);
       HAS_NEW_DNS_GET_DEFAULT_HOST_API = true;
     } catch (Exception e) {
-      HAS_NEW_DNS_GET_DEFAULT_HOST_API = false;
+      HAS_NEW_DNS_GET_DEFAULT_HOST_API = false; // FindBugs: Causes REC_CATCH_EXCEPTION.
Suppressed
     }
   }
 

http://git-wip-us.apache.org/repos/asf/hbase/blob/ab0651ed/hbase-common/src/main/java/org/apache/hadoop/hbase/util/DynamicClassLoader.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/DynamicClassLoader.java
b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/DynamicClassLoader.java
index c1194ca..bc86358 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/DynamicClassLoader.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/DynamicClassLoader.java
@@ -99,7 +99,9 @@ public class DynamicClassLoader extends ClassLoaderBase {
     }
   }
 
-  private void initTempDir(final Configuration conf) {
+  // FindBugs: Making synchronized to avoid IS2_INCONSISTENT_SYNC complaints about
+  // remoteDirFs and jarModifiedTime being part synchronized protected.
+  private synchronized void initTempDir(final Configuration conf) {
     jarModifiedTime = new HashMap<String, Long>();
     String localDirPath = conf.get(
       LOCAL_DIR_KEY, DEFAULT_LOCAL_DIR) + DYNAMIC_JARS_DIR;

http://git-wip-us.apache.org/repos/asf/hbase/blob/ab0651ed/hbase-common/src/main/java/org/apache/hadoop/hbase/util/PrettyPrinter.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/PrettyPrinter.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/PrettyPrinter.java
index 2b59967..5f927cc 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/PrettyPrinter.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/PrettyPrinter.java
@@ -30,6 +30,8 @@ public class PrettyPrinter {
     NONE
   }
 
+  @edu.umd.cs.findbugs.annotations.SuppressWarnings(value="DM_BOXED_PRIMITIVE_FOR_PARSING",
+      justification="I don't get what FB is complaining about")
   public static String format(final String value, final Unit unit) {
     StringBuilder human = new StringBuilder();
     switch (unit) {

http://git-wip-us.apache.org/repos/asf/hbase/blob/ab0651ed/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Threads.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Threads.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Threads.java
index 5e76fff..ef8fe43 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Threads.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Threads.java
@@ -266,8 +266,8 @@ public class Threads {
     t.setUncaughtExceptionHandler(LOGGING_EXCEPTION_HANDLER);
   }
 
-  private static Method printThreadInfoMethod = null;
-  private static boolean printThreadInfoMethodWithPrintStream = true;
+  private static Method PRINT_THREAD_INFO_METHOD = null;
+  private static boolean PRINT_THREAD_INFO_METHOD_WITH_PRINTSTREAM = true;
 
   /**
    * Print all of the thread's information and stack traces. Wrapper around Hadoop's method.
@@ -275,31 +275,30 @@ public class Threads {
    * @param stream the stream to
    * @param title a string title for the stack trace
    */
-  public static void printThreadInfo(PrintStream stream, String title) {
-
-    if (printThreadInfoMethod == null) {
+  public static synchronized void printThreadInfo(PrintStream stream, String title) {
+    if (PRINT_THREAD_INFO_METHOD == null) {
       try {
         // Hadoop 2.7+ declares printThreadInfo(PrintStream, String)
-        printThreadInfoMethod = ReflectionUtils.class.getMethod("printThreadInfo",
+        PRINT_THREAD_INFO_METHOD = ReflectionUtils.class.getMethod("printThreadInfo",
           PrintStream.class, String.class);
       } catch (NoSuchMethodException e) {
         // Hadoop 2.6 and earlier declares printThreadInfo(PrintWriter, String)
-        printThreadInfoMethodWithPrintStream = false;
+        PRINT_THREAD_INFO_METHOD_WITH_PRINTSTREAM = false;
         try {
-          printThreadInfoMethod = ReflectionUtils.class.getMethod("printThreadInfo",
+          PRINT_THREAD_INFO_METHOD = ReflectionUtils.class.getMethod("printThreadInfo",
             PrintWriter.class, String.class);
         } catch (NoSuchMethodException e1) {
           throw new RuntimeException("Cannot find method. Check hadoop jars linked", e1);
         }
       }
-      printThreadInfoMethod.setAccessible(true);
+      PRINT_THREAD_INFO_METHOD.setAccessible(true);
     }
 
     try {
-      if (printThreadInfoMethodWithPrintStream) {
-        printThreadInfoMethod.invoke(null, stream, title);
+      if (PRINT_THREAD_INFO_METHOD_WITH_PRINTSTREAM) {
+        PRINT_THREAD_INFO_METHOD.invoke(null, stream, title);
       } else {
-        printThreadInfoMethod.invoke(null, new PrintWriter(stream), title);
+        PRINT_THREAD_INFO_METHOD.invoke(null, new PrintWriter(stream), title);
       }
     } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException
e) {
       throw new RuntimeException(e.getCause());

http://git-wip-us.apache.org/repos/asf/hbase/blob/ab0651ed/hbase-common/src/main/java/org/apache/hadoop/hbase/util/UnsafeAccess.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/UnsafeAccess.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/UnsafeAccess.java
index 1a34607..1a0b0e9 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/UnsafeAccess.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/UnsafeAccess.java
@@ -32,6 +32,8 @@ import sun.misc.Unsafe;
 
 @InterfaceAudience.Private
 @InterfaceStability.Evolving
+@edu.umd.cs.findbugs.annotations.SuppressWarnings(value="REC_CATCH_EXCEPTION",
+  justification="If exception, presume unaligned")
 public final class UnsafeAccess {
 
   private static final Log LOG = LogFactory.getLog(UnsafeAccess.class);
@@ -66,7 +68,7 @@ public final class UnsafeAccess {
         m.setAccessible(true);
         unaligned = (boolean) m.invoke(null);
       } catch (Exception e) {
-        unaligned = false;
+        unaligned = false; // FindBugs: Causes REC_CATCH_EXCEPTION. Suppressed.
       }
     } else{
       BYTE_ARRAY_BASE_OFFSET = -1;


Mime
View raw message