HBASE-15087 Fix hbase-common findbugs complaints

This commit is contained in:
stack 2016-01-14 17:18:16 -08:00
parent f8427aba2b
commit 546adefcd6
10 changed files with 50 additions and 19 deletions

View File

@ -92,6 +92,19 @@ public class JitterScheduledThreadPoolExecutorImpl extends ScheduledThreadPoolEx
return wrapped.compareTo(o); return wrapped.compareTo(o);
} }
@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 @Override
public void run() { public void run() {
wrapped.run(); wrapped.run();
@ -123,5 +136,4 @@ public class JitterScheduledThreadPoolExecutorImpl extends ScheduledThreadPoolEx
return wrapped.get(timeout, unit); return wrapped.get(timeout, unit);
} }
} }
} }

View File

@ -35,7 +35,7 @@ import org.apache.hadoop.hbase.util.NonceKey;
*/ */
@InterfaceAudience.Public @InterfaceAudience.Public
@InterfaceStability.Evolving @InterfaceStability.Evolving
public class ProcedureInfo { public class ProcedureInfo implements Cloneable {
private final long procId; private final long procId;
private final String procName; private final String procName;
private final String procOwner; private final String procOwner;
@ -72,6 +72,8 @@ public class ProcedureInfo {
this.result = result; 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() { public ProcedureInfo clone() {
return new ProcedureInfo( return new ProcedureInfo(
procId, procName, procOwner, procState, parentId, exception, lastUpdate, startTime, result); procId, procName, procOwner, procState, parentId, exception, lastUpdate, startTime, result);

View File

@ -42,10 +42,11 @@ public class SpanReceiverHost {
private Configuration conf; private Configuration conf;
private boolean closed = false; private boolean closed = false;
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value="SE_BAD_FIELD")
private static enum SingletonHolder { private static enum SingletonHolder {
INSTANCE; INSTANCE;
Object lock = new Object(); Object lock = new Object();
SpanReceiverHost host = null; SpanReceiverHost host = null; // FindBugs: SE_BAD_FIELD
} }
public static SpanReceiverHost getInstance(Configuration conf) { public static SpanReceiverHost getInstance(Configuration conf) {

View File

@ -27,6 +27,7 @@ import java.util.Comparator;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.NavigableSet; import java.util.NavigableSet;
import java.util.NoSuchElementException;
import java.util.Set; import java.util.Set;
import java.util.SortedSet; import java.util.SortedSet;
import java.util.concurrent.ConcurrentNavigableMap; import java.util.concurrent.ConcurrentNavigableMap;
@ -693,8 +694,10 @@ public class CopyOnWriteArrayMap<K, V> extends AbstractMap<K, V>
} }
@Override @Override
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value="EQ_ALWAYS_FALSE",
justification="Intentional")
public boolean equals(Object o) { public boolean equals(Object o) {
return false; return false; // FindBugs: Causes EQ_ALWAYS_FALSE. Suppressed.
} }
@Override @Override
@ -771,7 +774,12 @@ public class CopyOnWriteArrayMap<K, V> extends AbstractMap<K, V>
} }
@Override @Override
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value="IT_NO_SUCH_ELEMENT",
justification="Intentional")
public Entry<K, V> next() { public Entry<K, V> next() {
if (!hasNext()) {
throw new NoSuchElementException();
}
return holder.entries[index++]; return holder.entries[index++];
} }

View File

@ -32,6 +32,7 @@ import org.apache.hadoop.io.WritableUtils;
* Utility functions for working with byte buffers, such as reading/writing * Utility functions for working with byte buffers, such as reading/writing
* variable-length long numbers. * variable-length long numbers.
*/ */
@SuppressWarnings("restriction")
@InterfaceAudience.Public @InterfaceAudience.Public
@InterfaceStability.Evolving @InterfaceStability.Evolving
public final class ByteBufferUtils { public final class ByteBufferUtils {

View File

@ -25,6 +25,8 @@ import org.apache.hadoop.hbase.classification.InterfaceAudience;
* Wrapper around Hadoop's DNS class to hide reflection. * Wrapper around Hadoop's DNS class to hide reflection.
*/ */
@InterfaceAudience.Private @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 { public final class DNS {
private static boolean HAS_NEW_DNS_GET_DEFAULT_HOST_API; private static boolean HAS_NEW_DNS_GET_DEFAULT_HOST_API;
private static Method GET_DEFAULT_HOST_METHOD; private static Method GET_DEFAULT_HOST_METHOD;
@ -35,7 +37,7 @@ public final class DNS {
.getMethod("getDefaultHost", String.class, String.class, boolean.class); .getMethod("getDefaultHost", String.class, String.class, boolean.class);
HAS_NEW_DNS_GET_DEFAULT_HOST_API = true; HAS_NEW_DNS_GET_DEFAULT_HOST_API = true;
} catch (Exception e) { } 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
} }
} }

View File

@ -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>(); jarModifiedTime = new HashMap<String, Long>();
String localDirPath = conf.get( String localDirPath = conf.get(
LOCAL_DIR_KEY, DEFAULT_LOCAL_DIR) + DYNAMIC_JARS_DIR; LOCAL_DIR_KEY, DEFAULT_LOCAL_DIR) + DYNAMIC_JARS_DIR;

View File

@ -30,6 +30,8 @@ public class PrettyPrinter {
NONE 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) { public static String format(final String value, final Unit unit) {
StringBuilder human = new StringBuilder(); StringBuilder human = new StringBuilder();
switch (unit) { switch (unit) {

View File

@ -266,8 +266,8 @@ public class Threads {
t.setUncaughtExceptionHandler(LOGGING_EXCEPTION_HANDLER); t.setUncaughtExceptionHandler(LOGGING_EXCEPTION_HANDLER);
} }
private static Method printThreadInfoMethod = null; private static Method PRINT_THREAD_INFO_METHOD = null;
private static boolean printThreadInfoMethodWithPrintStream = true; 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. * 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 stream the stream to
* @param title a string title for the stack trace * @param title a string title for the stack trace
*/ */
public static void printThreadInfo(PrintStream stream, String title) { public static synchronized void printThreadInfo(PrintStream stream, String title) {
if (PRINT_THREAD_INFO_METHOD == null) {
if (printThreadInfoMethod == null) {
try { try {
// Hadoop 2.7+ declares printThreadInfo(PrintStream, String) // Hadoop 2.7+ declares printThreadInfo(PrintStream, String)
printThreadInfoMethod = ReflectionUtils.class.getMethod("printThreadInfo", PRINT_THREAD_INFO_METHOD = ReflectionUtils.class.getMethod("printThreadInfo",
PrintStream.class, String.class); PrintStream.class, String.class);
} catch (NoSuchMethodException e) { } catch (NoSuchMethodException e) {
// Hadoop 2.6 and earlier declares printThreadInfo(PrintWriter, String) // Hadoop 2.6 and earlier declares printThreadInfo(PrintWriter, String)
printThreadInfoMethodWithPrintStream = false; PRINT_THREAD_INFO_METHOD_WITH_PRINTSTREAM = false;
try { try {
printThreadInfoMethod = ReflectionUtils.class.getMethod("printThreadInfo", PRINT_THREAD_INFO_METHOD = ReflectionUtils.class.getMethod("printThreadInfo",
PrintWriter.class, String.class); PrintWriter.class, String.class);
} catch (NoSuchMethodException e1) { } catch (NoSuchMethodException e1) {
throw new RuntimeException("Cannot find method. Check hadoop jars linked", e1); throw new RuntimeException("Cannot find method. Check hadoop jars linked", e1);
} }
} }
printThreadInfoMethod.setAccessible(true); PRINT_THREAD_INFO_METHOD.setAccessible(true);
} }
try { try {
if (printThreadInfoMethodWithPrintStream) { if (PRINT_THREAD_INFO_METHOD_WITH_PRINTSTREAM) {
printThreadInfoMethod.invoke(null, stream, title); PRINT_THREAD_INFO_METHOD.invoke(null, stream, title);
} else { } else {
printThreadInfoMethod.invoke(null, new PrintWriter(stream), title); PRINT_THREAD_INFO_METHOD.invoke(null, new PrintWriter(stream), title);
} }
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
throw new RuntimeException(e.getCause()); throw new RuntimeException(e.getCause());

View File

@ -32,6 +32,8 @@ import sun.misc.Unsafe;
@InterfaceAudience.Private @InterfaceAudience.Private
@InterfaceStability.Evolving @InterfaceStability.Evolving
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value="REC_CATCH_EXCEPTION",
justification="If exception, presume unaligned")
public final class UnsafeAccess { public final class UnsafeAccess {
private static final Log LOG = LogFactory.getLog(UnsafeAccess.class); private static final Log LOG = LogFactory.getLog(UnsafeAccess.class);
@ -66,7 +68,7 @@ public final class UnsafeAccess {
m.setAccessible(true); m.setAccessible(true);
unaligned = (boolean) m.invoke(null); unaligned = (boolean) m.invoke(null);
} catch (Exception e) { } catch (Exception e) {
unaligned = false; unaligned = false; // FindBugs: Causes REC_CATCH_EXCEPTION. Suppressed.
} }
} else{ } else{
BYTE_ARRAY_BASE_OFFSET = -1; BYTE_ARRAY_BASE_OFFSET = -1;