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);
}
@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);
}
}
}

View File

@ -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);

View File

@ -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) {

View File

@ -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++];
}

View File

@ -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 {

View File

@ -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
}
}

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

View File

@ -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) {

View File

@ -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());

View File

@ -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;