FindBugs Report 解讀(二)

續(xù)接:FindBugs Report 解讀(一)

四隙券、Correctness關(guān)于代碼正確性相關(guān)方面的

1.BC: Impossible cast (BC_IMPOSSIBLE_CAST)

不可能的類轉(zhuǎn)換,執(zhí)行時會拋出ClassCastException

2.BC: Impossible downcast (BC_IMPOSSIBLE_DOWNCAST)

父類在向下進(jìn)行類型轉(zhuǎn)換時拋出ClassCastException

3.BC: Impossible downcast of toArray() result (BC_IMPOSSIBLE_DOWNCAST_OF_TOARRAY)

集合轉(zhuǎn)換為數(shù)組元素時發(fā)生的類轉(zhuǎn)換錯誤闹司。

This code is casting the result of calling toArray() on a collection to a type more specific than Object[], as in:?

String[] getAsArray(Collection<String> c) {

? return (String[]) c.toArray();

? }

This

will usually fail by throwing a ClassCastException. The toArray() of

almost all collections return an Object[]. They can't really do anything

else, since the Collection object has no reference to the declared

generic type of the collection.?

The correct way to do get an

array of a specific type from a collection is to use c.toArray(new

String[]); or c.toArray(new String[c.size()]); (the latter is slightly

more efficient).?

4.BC: instanceof will always return false (BC_IMPOSSIBLE_INSTANCEOF)

采用instaneof方法進(jìn)行比較時總是返回false娱仔。前提是保證它不是由于某些邏輯錯誤造成的。

5.BIT: Incompatible bit masks (BIT_AND)

錯誤的使用&位操作符游桩,例如(e & C)

6.BIT: Check to see if ((...) & 0) == 0 (BIT_AND_ZZ)

檢查恒等的邏輯錯誤

7.BIT: Incompatible bit masks (BIT_IOR)

錯誤的使用|位操作符牲迫,例如(e | C)

8.BIT: Check for sign of bitwise operation (BIT_SIGNED_CHECK_HIGH_BIT)

檢查邏輯運(yùn)算符操作返回的標(biāo)識。例如((event.detail & SWT.SELECTED) > 0)借卧,建議采用!=0代替>0

9.BOA: Class overrides a method implemented in super class Adapter wrongly (BOA_BADLY_OVERRIDDEN_ADAPTER)

子類錯誤的覆寫父類中用于適配監(jiān)聽其他事件的方法恩溅,從而導(dǎo)致當(dāng)觸發(fā)條件發(fā)生時不能被監(jiān)聽者調(diào)用

10.Bx: Primitive value is unboxed and coerced for ternary operator (BX_UNBOXED_AND_COERCED_FOR_TERNARY_OPERATOR)

在三元運(yùn)算符操作時如果沒有對值進(jìn)行封裝或者類型轉(zhuǎn)換。例如:b ? e1 : e2

11.DLS: Dead store of class literal (DLS_DEAD_STORE_OF_CLASS_LITERAL)

以類的字面名稱方式為一個字段賦值后再也沒有去使用它谓娃,在1.4jdk中它會自動調(diào)用靜態(tài)的初始化方法脚乡,而在jdk1.5中卻不會去執(zhí)行。

12.DLS: Overwritten increment (DLS_OVERWRITTEN_INCREMENT)

覆寫增量增加錯誤i = i++

13.DMI: Bad constant value for month (DMI_BAD_MONTH)

hashNext方法調(diào)用next方法。

14.DMI: Collections should not contain themselves (DMI_COLLECTIONS_SHOULD_NOT_CONTAIN_THEMSELVES)

集合沒有包含他們自己本身奶稠。

15.DMI: Invocation of hashCode on an array (DMI_INVOKING_HASHCODE_ON_ARRAY)

數(shù)組直接使用hashCode方法來返回哈希碼俯艰。

int [] a1 = new int[]{1,2,3,4};

System.out.println(a1.hashCode());

System.out.println(java.util.Arrays.hashCode(a1));

16.DMI: Double.longBitsToDouble invoked on an int (DMI_LONG_BITS_TO_DOUBLE_INVOKED_ON_INT)

17.DMI: Vacuous call to collections (DMI_VACUOUS_SELF_COLLECTION_CALL)

集合的調(diào)用不能被感知。例如c.containsAll(c)總是返回true锌订,而c.retainAll(c)的返回值不能被感知竹握。

18.Dm:

Can't use reflection to check for presence of annotation without

runtime retention (DMI_ANNOTATION_IS_NOT_VISIBLE_TO_REFLECTION)

Unless

an annotation has itself been annotated with

@Retention(RetentionPolicy.RUNTIME), the annotation can't be observed

using reflection (e.g., by using the isAnnotationPresent method). .

19.Dm: Useless/vacuous call to EasyMock method (DMI_VACUOUS_CALL_TO_EASYMOCK_METHOD)

While

ScheduledThreadPoolExecutor inherits from ThreadPoolExecutor, a few of

the inherited tuning methods are not useful for it. In particular,

because it acts as a fixed-sized pool using corePoolSize threads and an

unbounded queue, adjustments to maximumPoolSize have no useful effect.

20.EC: equals() used to compare array and nonarray (EC_ARRAY_AND_NONARRAY)

數(shù)組對象使用equals方法和非數(shù)組對象進(jìn)行比較。即使比較的雙方都是數(shù)組對象也不應(yīng)該使用equals方法辆飘,而應(yīng)該比較它們的內(nèi)容是否相等使用java.util.Arrays.equals(Object[], Object[]);

21.EC: equals(...) used to compare incompatible arrays (EC_INCOMPATIBLE_ARRAY_COMPARE)

使用equls方法去比較類型不相同的數(shù)組啦辐。例如:String[] and StringBuffer[], or String[] and int[]

22.EC: Call to equals() with null argument (EC_NULL_ARG)

調(diào)用equals的對象為null

23.EC: Call to equals() comparing unrelated class and interface (EC_UNRELATED_CLASS_AND_INTERFACE)

使用equals方法比較不相關(guān)的類和接口

24.EC: Call to equals() comparing different interface types (EC_UNRELATED_INTERFACES)

調(diào)用equals方法比較不同類型的接口

25.EC: Call to equals() comparing different types (EC_UNRELATED_TYPES)

調(diào)用equals方法比較不同類型的類

26.EC: Using pointer equality to compare different types (EC_UNRELATED_TYPES_USING_POINTER_EQUALITY)

This

method uses using pointer equality to compare two references that seem

to be of different types. The result of this comparison will always be

false at runtime.

27.Eq: equals method always returns false (EQ_ALWAYS_FALSE)

使用equals方法返回值總是false

28.Eq: equals method always returns true (EQ_ALWAYS_TRUE)

equals方法返回值總是true

29.Eq: equals method compares class names rather than class objects (EQ_COMPARING_CLASS_NAMES)

使用equals方法去比較一個類的實例和類的類型

30.Eq: Covariant equals() method defined for enum (EQ_DONT_DEFINE_EQUALS_FOR_ENUM)

This

class defines an enumeration, and equality on enumerations are defined

using object identity. Defining a covariant equals method for an

enumeration value is exceptionally bad practice, since it would likely

result in having two different enumeration values that compare as equals

using the covariant enum method, and as not equal when compared

normally. Don't do it.

31.Eq: equals() method defined that doesn't override equals(Object) (EQ_OTHER_NO_OBJECT)

類中定義的equals方法時不要覆寫equals(Object)方法

32.Eq: equals() method defined that doesn't override Object.equals(Object) (EQ_OTHER_USE_OBJECT)

類中定義的equals方法時不要覆寫Object中的equals(Object)方法

33.Eq: equals method overrides equals in superclass and may not be symmetric (EQ_OVERRIDING_EQUALS_NOT_SYMMETRIC)

34.Eq: Covariant equals() method defined, Object.equals(Object) inherited (EQ_SELF_USE_OBJECT)

類中定義了一組equals方法,但是都是繼承的java.lang.Object class中的equals(Object)方法

35.FE: Doomed test for equality to NaN (FE_TEST_IF_EQUAL_TO_NOT_A_NUMBER)

This

code checks to see if a floating point value is equal to the special

Not A Number value (e.g., if (x == Double.NaN)). However, because of the

special semantics of NaN, no value is equal to Nan, including NaN.

Thus, x == Double.NaN always evaluates to false. To check to see if a

value contained in x is the special Not A Number value, use

Double.isNaN(x) (or Float.isNaN(x) if x is floating point precision).

36.FS: Format string placeholder incompatible with passed argument (VA_FORMAT_STRING_BAD_ARGUMENT)

錯誤使用參數(shù)類型來格式化字符串

37.FS: The type of a supplied argument doesn't match format specifier (VA_FORMAT_STRING_BAD_CONVERSION)

指定的格式字符串和參數(shù)類型不匹配蜈项,例如:String.format("%d", "1")

38.FS: MessageFormat supplied where printf style format expected (VA_FORMAT_STRING_EXPECTED_MESSAGE_FORMAT_SUPPLIED)

但用String的format方法時實際調(diào)用了MessageFormat中干的格式化方法而引起格式化結(jié)果出錯芹关。

39.FS: More arguments are passed than are actually used in the format string (VA_FORMAT_STRING_EXTRA_ARGUMENTS_PASSED)

使用String的format方法時有非法的參數(shù)也經(jīng)過了格式化操作。

40.FS: Illegal format string (VA_FORMAT_STRING_ILLEGAL)

格式化String對象語句錯誤

41.FS: Format string references missing argument (VA_FORMAT_STRING_MISSING_ARGUMENT)

String的format操作缺少必要的參數(shù)紧卒。

42.FS: No previous argument for format string (VA_FORMAT_STRING_NO_PREVIOUS_ARGUMENT)

格式字符串定義錯誤侥衬,例如:formatter.format("%<s %s", "a", "b"); 拋出MissingFormatArgumentException異常

43.GC: No relationship between generic parameter and method argument (GC_UNRELATED_TYPES)

This

call to a generic collection method contains an argument with an

incompatible class from that of the collection's parameter (i.e., the

type of the argument is neither a supertype nor a subtype of the

corresponding generic type argument). Therefore, it is unlikely that the

collection contains any objects that are equal to the method argument

used here. Most likely, the wrong value is being passed to the method.

In

general, instances of two unrelated classes are not equal. For example,

if the Foo and Bar classes are not related by subtyping, then an

instance of Foo should not be equal to an instance of Bar. Among other

issues, doing so will likely result in an equals method that is not

symmetrical. For example, if you define the Foo class so that a Foo can

be equal to a String, your equals method isn't symmetrical since a

String can only be equal to a String.?

In rare cases, people do

define nonsymmetrical equals methods and still manage to make their code

work. Although none of the APIs document or guarantee it, it is

typically the case that if you check if a Collection<String>

contains a Foo, the equals method of argument (e.g., the equals method

of the Foo class) used to perform the equality checks.?

44.HE: Signature declares use of unhashable class in hashed construct (HE_SIGNATURE_DECLARES_HASHING_OF_UNHASHABLE_CLASS)

A

method, field or class declares a generic signature where a

non-hashable class is used in context where a hashable class is

required. A class that declares an equals method but inherits a

hashCode() method from Object is unhashable, since it doesn't fulfill

the requirement that equal objects have equal hashCodes.

45.HE: Use of class without a hashCode() method in a hashed data structure (HE_USE_OF_UNHASHABLE_CLASS)

A

class defines an equals(Object) method but not a hashCode() method, and

thus doesn't fulfill the requirement that equal objects have equal

hashCodes. An instance of this class is used in a hash data structure,

making the need to fix this problem of highest importance.

46.ICAST: integral value cast to double and then passed to Math.ceil (ICAST_INT_CAST_TO_DOUBLE_PASSED_TO_CEIL)

integral的值轉(zhuǎn)換為double后使用了Math.ceil方法

47.ICAST: int value cast to float and then passed to Math.round (ICAST_INT_CAST_TO_FLOAT_PASSED_TO_ROUND)

int 類型的值轉(zhuǎn)換為float類型之后調(diào)用了Math.round方法

48.IJU: JUnit assertion in run method will not be noticed by JUnit (IJU_ASSERT_METHOD_INVOKED_FROM_RUN_METHOD)

在JUnit中的斷言在run方法中不會被告知

49.IJU: TestCase declares a bad suite method (IJU_BAD_SUITE_METHOD)

在一個JUnit類中聲明的一個suite()方法必須聲明為

public static junit.framework.Test suite()

或者

public static junit.framework.TestSuite suite()的形式。

50.IL: A collection is added to itself (IL_CONTAINER_ADDED_TO_ITSELF)

集合本身作為add方法的參數(shù)跑芳,這樣會引起內(nèi)容溢出轴总。

51.IL: An apparent infinite loop (IL_INFINITE_LOOP)

方法的自調(diào)用引起的死循環(huán)

52.IM: Integer multiply of result of integer remainder (IM_MULTIPLYING_RESULT_OF_IREM)

和整數(shù)余數(shù)進(jìn)行乘法運(yùn)算。例如:i % 60 * 1000 是進(jìn)行(i % 60) * 1000運(yùn)算而不是 i % (60 * 1000)

53.INT: Bad comparison of nonnegative value with negative constant (INT_BAD_COMPARISON_WITH_NONNEGATIVE_VALUE)

保證非負(fù)數(shù)和負(fù)數(shù)進(jìn)行比較

54.INT: Bad comparison of signed byte (INT_BAD_COMPARISON_WITH_SIGNED_BYTE)

比較有符合數(shù)博个,要先把有符號數(shù)轉(zhuǎn)換為無符合數(shù)再進(jìn)行比較

55.IO: Doomed attempt to append to an object output stream (IO_APPENDING_TO_OBJECT_OUTPUT_STREAM)

宣布試圖在對象的輸出流處添加元素怀樟,如果你希望能夠添加進(jìn)一個對象的輸出流中必須保證對象的輸出流處于打開狀態(tài)。

56.IP: A parameter is dead upon entry to a method but overwritten (IP_PARAMETER_IS_DEAD_BUT_OVERWRITTEN)

The

initial value of this parameter is ignored, and the parameter is

overwritten here. This often indicates a mistaken belief that the write

to the parameter will be conveyed back to the caller.

傳入?yún)?shù)的值被忽略盆佣,但是對傳入值進(jìn)行了修改往堡,并返回給了調(diào)用者

57.MF: Class defines field that masks a superclass field (MF_CLASS_MASKS_FIELD)

子類中定義了和父類中同名的字段。在調(diào)用時會出錯

58.MF: Method defines a variable that obscures a field (MF_METHOD_MASKS_FIELD)

在方法中定義的局部變量和類變量或者父類變量同名罪塔,從而引起字段混淆。

59.NP: Null pointer dereference (NP_ALWAYS_NULL)

對象賦為null值后 沒有被重新賦值

60.NP: Null pointer dereference in method on exception path (NP_ALWAYS_NULL_EXCEPTION)

A

pointer which is null on an exception path is dereferenced here. ?This

will lead to a NullPointerException when the code is executed. ?Note

that because FindBugs currently does not prune infeasible exception

paths, this may be a false warning.

Also note that FindBugs

considers the default case of a switch statement to be an exception

path, since the default case is often infeasible.

空指針引用上調(diào)用去除引用方法养葵,將發(fā)生空指針異常

61.NP: Method does not check for null argument (NP_ARGUMENT_MIGHT_BE_NULL)

方法沒有判斷參數(shù)是否為空

62.NP: close() invoked on a value that is always null (NP_CLOSING_NULL)

一個為空的對象調(diào)用close方法

63.NP: Null value is guaranteed to be dereferenced (NP_GUARANTEED_DEREF)

There

is a statement or branch that if executed guarantees that a value is

null at this point, and that value that is guaranteed to be dereferenced

(except on forward paths involving runtime exceptions).

在正常的null判斷分支上征堪,對象去除引用操作是受保護(hù)的不允許的

64.NP: Value is null and guaranteed to be dereferenced on exception path (NP_GUARANTEED_DEREF_ON_EXCEPTION_PATH)

There

is a statement or branch on an exception path that if executed

guarantees that a value is null at this point, and that value that is

guaranteed to be dereferenced (except on forward paths involving runtime

exceptions).

65.NP: Method call passes null to a nonnull parameter (NP_NONNULL_PARAM_VIOLATION)

方法中為null的參數(shù)沒有被重新賦值

void test(){

String ss = null;

sya(ss);

}

public void sya(String ad){

ad.getBytes();

}

66.NP: Method may return null, but is declared @NonNull (NP_NONNULL_RETURN_VIOLATION)

方法聲明了返回值不能為空,但是方法中有可能返回null

67.NP: A known null value is checked to see if it is an instance of a type (NP_NULL_INSTANCEOF)

檢查一個為null的值是否是想要的類型對象关拒,而不是由于粗心或者邏輯錯誤引起的

68.NP: Possible null pointer dereference (NP_NULL_ON_SOME_PATH)

對象可能沒有重新賦值

69.NP: Possible null pointer dereference in method on exception path (NP_NULL_ON_SOME_PATH_EXCEPTION)

A

reference value which is null on some exception control path is

dereferenced here. ?This may lead to a NullPointerException when the

code is executed. ?Note that because FindBugs currently does not prune

infeasible exception paths, this may be a false warning.

Also note

that FindBugs considers the default case of a switch statement to be an

exception path, since the default case is often infeasible.

在異常null值處理分支調(diào)用的方法上佃蚜,可能存在對象去除引用操作

70.NP: Method call passes null for nonnull parameter (NP_NULL_PARAM_DEREF_ALL_TARGETS_DANGEROUS)

方法參數(shù)中聲明為nonnull類型的參數(shù)為null

void test(){

String ss = null;

sya(ss);

}

public void sya(@nonnull String ad){

ad.getBytes();

}

71.NP: Store of null value into field annotated NonNull (NP_STORE_INTO_NONNULL_FIELD)

為一個已經(jīng)聲明為不能為null值的屬性賦值為null。

72.Nm: Class defines equal(Object); should it be equals(Object)? (NM_BAD_EQUAL)

類中定義了一個equal方法但是卻不是覆寫的Object對象的equals方法

73.Nm: Class defines hashcode(); should it be hashCode()? (NM_LCASE_HASHCODE)

類中定義了一個hashCode方法但是卻不是覆寫的Object中的hashCode方法

74.Nm: Class defines tostring(); should it be toString()? (NM_LCASE_TOSTRING)

類中定義了一個toString方法但是卻不是覆寫的Object中的toString方法

75.Nm: Apparent method/constructor confusion (NM_METHOD_CONSTRUCTOR_CONFUSION)

構(gòu)造方法定義混亂着绊,保證一個標(biāo)準(zhǔn)的構(gòu)造函數(shù)谐算。例如:

SA(){}

void SA(){

}

76.Nm: Very confusing method names (NM_VERY_CONFUSING)

混亂的方法命名,如getName和getname方法同時出現(xiàn)的時候

77.Nm: Method doesn't override method in superclass due to wrong package for parameter (NM_WRONG_PACKAGE)

方法因為取了不同包中的同名的對象而沒有正確覆寫父類中的同名方法

import alpha.Foo;

public class A {

? public int f(Foo x) { return 17; }

}

----

import beta.Foo;

public class B extends A {

? public int f(Foo x) { return 42; }

}

78.QBA: Method assigns boolean literal in boolean expression (QBA_QUESTIONABLE_BOOLEAN_ASSIGNMENT)

再if或者while表達(dá)式中使用boolean類型的值時應(yīng)該使用==去判斷归露,而不是采用=操作

79.RC: Suspicious reference comparison (RC_REF_COMPARISON)

比較兩個對象值是否相等時應(yīng)該采用equals方法洲脂,而不是==方法

80.RE: Invalid syntax for regular expression (RE_BAD_SYNTAX_FOR_REGULAR_EXPRESSION)

對正則表達(dá)式使用了錯誤的語法,會拋出未經(jīng)檢查的異常剧包,表明正則表達(dá)式模式中的語法錯誤恐锦。

81.RE: File.separator used for regular expression (RE_CANT_USE_FILE_SEPARATOR_AS_REGULAR_EXPRESSION)

使用正則表達(dá)式使用了錯誤的文件分隔符往果,在windows系統(tǒng)中正則表達(dá)式不會匹配’\’而應(yīng)該使用'\\'

82.RV: Random value from 0 to 1 is coerced to the integer 0 (RV_01_TO_INT)

從0到1隨機(jī)值被強(qiáng)制為整數(shù)值0。在強(qiáng)制得到一個整數(shù)之前一铅,你可能想得到多個隨機(jī)值陕贮。或使用Random.nextInt(n)的方法潘飘。

83.RV: Bad attempt to compute absolute value of signed 32-bit hashcode (RV_ABSOLUTE_VALUE_OF_HASHCODE)

此代碼生成一個哈希碼肮之,然后計算該哈希碼的絕對值。如果哈希碼是Integer.MIN_VALUE的卜录,那么結(jié)果將是負(fù)數(shù)(因為Math.abs(Integer.MIN_VALUE的)== Integer.MIN_VALUE的)戈擒。

在2^ 32值之外字符串有一個Integer.MIN_VALUE的hashCode包括“polygenelubricants”,“GydZG_”和“暴凑,”DESIGNING WORKHOUSES “峦甩。

84.RV: Bad attempt to compute absolute value of signed 32-bit random integer (RV_ABSOLUTE_VALUE_OF_RANDOM_INT)

此代碼生成一個隨機(jī)的符號整數(shù),然后計算該隨機(jī)整數(shù)的絕對值现喳。如果隨機(jī)數(shù)生成數(shù)絕對值為Integer.MIN_VALUE的凯傲,那么結(jié)果將是負(fù)數(shù)(因為Math.abs(Integer.MIN_VALUE的)== Integer.MIN_VALUE的)。

85.RV: Exception created and dropped rather than thrown (RV_EXCEPTION_NOT_THROWN)

此代碼創(chuàng)建一個異常(或錯誤)的對象嗦篱,但不會用它做任何事情冰单。例如:if (x < 0)

? new IllegalArgumentException("x must be nonnegative");

這可能是程序員的意圖拋出創(chuàng)建的異常:

if (x < 0)

? throw new IllegalArgumentException("x must be nonnegative");

86.RV: Method ignores return value (RV_RETURN_VALUE_IGNORED)

該方法的返回值應(yīng)該進(jìn)行檢查。這種警告通常出現(xiàn)在調(diào)用一個不可變對象的方法灸促,認(rèn)為它更新了對象的值诫欠。例如:String dateString = getHeaderField(name);

dateString.trim();

程序員似乎以為trim()方法將更新dateString引用的字符串。但由于字符串是不可改變的浴栽,trim()函數(shù)返回一個新字符串值荒叼,在這里它是被忽略了。該代碼應(yīng)更正:

String dateString = getHeaderField(name);

dateString = dateString.trim();

87.RpC: Repeated conditional tests (RpC_REPEATED_CONDITIONAL_TEST)

該代碼包含對同一個條件試驗了兩次典鸡,兩邊完全一樣例如:(如X == 0 | | x == 0)被廓。可能第二次出現(xiàn)是打算判斷別的不同條件(如X == 0 | | y== 0)萝玷。

88.SA: Double assignment of field (SA_FIELD_DOUBLE_ASSIGNMENT)

方法中的字段包含了雙重任務(wù)嫁乘,例如:?

?int x;

? public void foo() {

? ?x = x = 17;

? }

這種為變量賦值是無用的,并可能表明一個邏輯錯誤或拼寫錯誤球碉。

89.SA: Self assignment of field (SA_FIELD_SELF_ASSIGNMENT)

方法中包含自己對自己賦值的字段蜓斧。例如:

int x;

? public void foo() {

? ? x = x;

? }

90.SA: Self comparison of field with itself (SA_FIELD_SELF_COMPARISON)

字段自己進(jìn)行自比較可能表明錯誤或邏輯錯誤。

91.SA: Self comparison of value with itself (SA_LOCAL_SELF_COMPARISON)

方法中對一個局部變量自身進(jìn)行比較運(yùn)算睁冬,并可說明錯誤或邏輯錯誤挎春。請確保您是比較正確的事情。

92.SA: Nonsensical self computation involving a variable (e.g., x & x) (SA_LOCAL_SELF_COMPUTATION)

此方法對同一變量執(zhí)行了荒謬的計算(如x&x或x-x)操作。由于計算的性質(zhì)搂蜓,這一行動似乎沒有意義狼荞,并可能表明錯誤或邏輯錯誤。

93.SF: Dead store due to switch statement fall through (SF_DEAD_STORE_DUE_TO_SWITCH_FALLTHROUGH)

在swtich中先前的case值因為swtich執(zhí)行失敗而被覆寫帮碰,這就像是忘記使用break推出或者沒有使用return語句放回先前的值一樣相味。

94.SF: Dead store due to switch statement fall through to throw (SF_DEAD_STORE_DUE_TO_SWITCH_FALLTHROUGH_TO_THROW)

在swtich中因為出現(xiàn)異常而忽略了對case值的保存。

95.SIC: Deadly embrace of non-static inner class and thread local (SIC_THREADLOCAL_DEADLY_EMBRACE)

如果是一個靜態(tài)內(nèi)部類殉挽。實際上丰涉,在內(nèi)部類和當(dāng)前線程有死鎖的可能。由于內(nèi)部類不是靜態(tài)的斯碌,它保留了對外部類的引用一死。如果線程包含對一個內(nèi)部類實例的引用,那么內(nèi)外實例的實例都可以被獲取傻唾,這樣就不具備垃圾會回收的資格投慈。

96.SIO: Unnecessary type check done using instanceof operator (SIO_SUPERFLUOUS_INSTANCEOF)

在進(jìn)行instanceof操作時進(jìn)行沒有必要的類型檢查

97.STI: Unneeded use of currentThread() call, to call interrupted() (STI_INTERRUPTED_ON_CURRENTTHREAD)

此方法調(diào)用Thread.currentThread()調(diào)用,只需調(diào)用interrupted()方法冠骄。由于interrupted()是一個靜態(tài)方法伪煤, Thread.interrupted()更簡單易用。

98.STI: Static Thread.interrupted() method invoked on thread instance (STI_INTERRUPTED_ON_UNKNOWNTHREAD)

調(diào)用不是當(dāng)前線程對象的Thread.interrupted()方法凛辣,由于interrupted()方法是靜態(tài)的抱既,interrupted方法將會調(diào)用一個和作者原計劃不同的對象。

99.Se: Method must be private in order for serialization to work (SE_METHOD_MUST_BE_PRIVATE)

這個類實現(xiàn)了Serializable接口扁誓,并定義自定義序列化的方法/反序列化防泵。但由于這種方法不能聲明為private蝗敢,將被序列化/反序列化的API忽略掉捷泞。

100.Se: The readResolve method must not be declared as a static method. (SE_READ_RESOLVE_IS_STATIC)

為使readResolve方法得到序列化機(jī)制的識別,不能作為一個靜態(tài)方法來聲明寿谴。

101.UMAC: Uncallable method defined in anonymous class (UMAC_UNCALLABLE_METHOD_OF_ANONYMOUS_CLASS)

在匿名類中定義了一個既沒有覆寫超類中方法也不能直接調(diào)用的方法锁右。因為在其他類的方法不能直接引用匿名類聲明的方法,似乎這種方法不能被調(diào)用拭卿,這種方法可能只是沒有任何作用的代碼骡湖,但也可能覆寫超類中聲明贱纠。

102.UR: Uninitialized read of field in constructor (UR_UNINIT_READ)

此構(gòu)造方法中使用了一個尚未賦值的字段或?qū)傩浴?/p>

String a;

public SA() {

String abc = a;

System.out.println(abc);

}

103.UR: Uninitialized read of field method called from constructor of superclass (UR_UNINIT_READ_CALLED_FROM_SUPER_CONSTRUCTOR)

方法被超類的構(gòu)造函數(shù)調(diào)用時峻厚,在當(dāng)前類中的字段或?qū)傩赃€沒有被初始化。例如:

abstract class A {

? int hashCode;

? abstract Object getValue();

? A() {

? ? hashCode = getValue().hashCode();

? ? }

? }

class B extends A {

? Object value;

? B(Object v) {

? ? this.value = v;

? ? }

? Object getValue() {

? ? return value;

? }

? }

當(dāng)B是創(chuàng)建時谆焊,A的構(gòu)造函數(shù)將在B為value賦值之前觸發(fā)惠桃,然而在A的初始化方法調(diào)用getValue方法時value這個變量還沒有被初始化。

104.USELESS_STRING: Invocation of toString on an array (DMI_INVOKING_TOSTRING_ON_ANONYMOUS_ARRAY)

該代碼調(diào)用上匿名數(shù)組的toString()方法,產(chǎn)生的結(jié)果形如[@ 16f0472并沒有實際的意義辜王∨考慮使用Arrays.toString方法來轉(zhuǎn)換成可讀的字符串,提供該數(shù)組的內(nèi)容數(shù)組呐馆。例如:

String[] a = { "a" };

System.out.println(a.toString());

//正確的使用為

System.out.println(Arrays.toString(a));

105.USELESS_STRING: Invocation of toString on an array (DMI_INVOKING_TOSTRING_ON_ARRAY)

該代碼調(diào)用上數(shù)組的toString()方法肥缔,產(chǎn)生的結(jié)果形如[@ 16f0472并不能顯示數(shù)組的真實內(nèi)容⌒诶矗考慮使用Arrays.toString方法來轉(zhuǎn)換成可讀的字符串续膳,提供該數(shù)組的內(nèi)容數(shù)組

106.UwF: Field only ever set to null (UWF_NULL_FIELD)

字段的值總是為null值,所有讀取該字段的值都為null收班。檢查錯誤坟岔,如果它確實沒有用就刪除掉。

107.UwF: Unwritten field (UWF_UNWRITTEN_FIELD

此字段是永遠(yuǎn)不會寫入值摔桦。所有讀取將返回默認(rèn)值社付。檢查錯誤(如果它被初始化?)邻耕,如果它確實沒有用就刪除掉鸥咖。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市赊豌,隨后出現(xiàn)的幾起案子扛或,更是在濱河造成了極大的恐慌,老刑警劉巖碘饼,帶你破解...
    沈念sama閱讀 219,539評論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件熙兔,死亡現(xiàn)場離奇詭異,居然都是意外死亡艾恼,警方通過查閱死者的電腦和手機(jī)住涉,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,594評論 3 396
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來钠绍,“玉大人舆声,你說我怎么就攤上這事×” “怎么了媳握?”我有些...
    開封第一講書人閱讀 165,871評論 0 356
  • 文/不壞的土叔 我叫張陵,是天一觀的道長磷脯。 經(jīng)常有香客問我蛾找,道長,這世上最難降的妖魔是什么赵誓? 我笑而不...
    開封第一講書人閱讀 58,963評論 1 295
  • 正文 為了忘掉前任打毛,我火速辦了婚禮柿赊,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘幻枉。我一直安慰自己碰声,他們只是感情好,可當(dāng)我...
    茶點故事閱讀 67,984評論 6 393
  • 文/花漫 我一把揭開白布熬甫。 她就那樣靜靜地躺著胰挑,像睡著了一般。 火紅的嫁衣襯著肌膚如雪椿肩。 梳的紋絲不亂的頭發(fā)上洽腺,一...
    開封第一講書人閱讀 51,763評論 1 307
  • 那天,我揣著相機(jī)與錄音覆旱,去河邊找鬼蘸朋。 笑死,一個胖子當(dāng)著我的面吹牛扣唱,可吹牛的內(nèi)容都是我干的藕坯。 我是一名探鬼主播,決...
    沈念sama閱讀 40,468評論 3 420
  • 文/蒼蘭香墨 我猛地睜開眼噪沙,長吁一口氣:“原來是場噩夢啊……” “哼炼彪!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起正歼,我...
    開封第一講書人閱讀 39,357評論 0 276
  • 序言:老撾萬榮一對情侶失蹤辐马,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后局义,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體喜爷,經(jīng)...
    沈念sama閱讀 45,850評論 1 317
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 38,002評論 3 338
  • 正文 我和宋清朗相戀三年萄唇,在試婚紗的時候發(fā)現(xiàn)自己被綠了檩帐。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 40,144評論 1 351
  • 序言:一個原本活蹦亂跳的男人離奇死亡另萤,死狀恐怖湃密,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情四敞,我是刑警寧澤泛源,帶...
    沈念sama閱讀 35,823評論 5 346
  • 正文 年R本政府宣布,位于F島的核電站忿危,受9級特大地震影響达箍,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜癌蚁,卻給世界環(huán)境...
    茶點故事閱讀 41,483評論 3 331
  • 文/蒙蒙 一幻梯、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧努释,春花似錦碘梢、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,026評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至逸邦,卻和暖如春恩沛,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背缕减。 一陣腳步聲響...
    開封第一講書人閱讀 33,150評論 1 272
  • 我被黑心中介騙來泰國打工雷客, 沒想到剛下飛機(jī)就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人桥狡。 一個月前我還...
    沈念sama閱讀 48,415評論 3 373
  • 正文 我出身青樓搅裙,卻偏偏與公主長得像,于是被迫代替她去往敵國和親裹芝。 傳聞我的和親對象是個殘疾皇子部逮,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 45,092評論 2 355

推薦閱讀更多精彩內(nèi)容

  • pyspark.sql模塊 模塊上下文 Spark SQL和DataFrames的重要類: pyspark.sql...
    mpro閱讀 9,457評論 0 13
  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi閱讀 7,336評論 0 10
  • The Inner Game of Tennis W Timothy Gallwey Jonathan Cape ...
    網(wǎng)事_79a3閱讀 12,081評論 3 20
  • 金氏宗祠位于沅陵縣七甲坪鎮(zhèn)伍家灣社區(qū),系湖南省級文物保護(hù)單位嫂易。 金姓是七甲坪的大姓兄朋,其祖先原本是漢室宗親,王莽篡位...
    辰州強(qiáng)哥閱讀 3,099評論 0 2
  • 記憶中故鄉(xiāng)總與一縷炊煙有關(guān)怜械。 奶奶從煙熏火燎的鍋屋起身颅和,用那雙剛剛放下柴刀的粗糙皺褶的手,輕輕地在圍裙上擦拭著...
    郁青禾閱讀 260評論 0 3