Professional Documents
Culture Documents
FindBugs
1.0 cantellow 2011-5-24
1.1 2011-6-9
Pattern id Ctrl + F
Findbugs
1. EC_UNRELATED_TYPES
2. IM_BAD_CHECK_FOR_ODD
Bug: Check for oddness that won't work for negative numbers
Pattern id: IM_BAD_CHECK_FOR_ODD, type: IM, category: STYLE
row row % 2 == -1
x & 1 == 1 x % 2 != 0
3. NP_ALWAYS_NULL
Pattern: Null pointer dereference
id: NP_ALWAYS_NULL, type: NP, category: CORRECTNESS
4. RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE
5. SS_SHOULD_BE_STATIC
Bug: Unread field: ADDRESS_KEY; should this field be static?
Pattern id: SS_SHOULD_BE_STATIC, type: SS, category: PERFORMANCE
final
final
static
6. EQ_COMPARETO_USE_OBJECT_EQUALS
instanceof classcastexception
BUG (x.compareTo(y)==0) == (x.equals(y))
return 0 equals true PriorityQueue.remove 1.5
compareTo 1.6 equals
7. NM_METHOD_NAMING_CONVENTION
Methods should be verbs, in mixed case with the first letter lowercase,
with the first letter of each internal word capitalized.
8. HE_EQUALS_USE_HASHCODE
Bug: PerfmSingleGraphPanel$RSCategory defines equals and uses Object.hashCode()
Pattern id: HE_EQUALS_USE_HASHCODE, type: HE, category: BAD_PRACTICE
equals
HashMap/HashTable
hashcode
9. NM_CONFUSING
Bug: Confusing to have methods
xxx.SellerBrandServiceImpl.getAllGrantSellerBrandsByBrandId(long) and
xxx.DefaultSellerBrandManager.getALLGrantSellerBrandsByBrandId(long)
Pattern id: NM_CONFUSING, type: Nm, category: BAD_PRACTICE
10. MF_CLASS_MASKS_FIELD
This class defines a field with the same name as a visible instance field
in a superclass. This is confusing, and may indicate an error if methods
update or access one of the fields when they wanted the other.
m_instance
11. NM_CLASS_NAMING_CONVENTION
Bug: The class name crossConnectIndexCollecter doesn't start with an upper case letter
12. RE_POSSIBLE_UNINTENDED_PATTERN
String split
. $ ^ {}[] ()
| * + ?\\
\\
13.IA_AMBIGUOUS_INVOCATION_OF_INHERITED_OR_OU
TER_METHOD
TargetSetupDialog JExtendDialog
JExtendDialog onOK JExtendDialog
onOK onOK onOK
onOK
JExtendDialog onOK
JExtendDialog onOK onOK
this.onOK this
outclass.this
onOK super.onOK()
14. DM_FP_NUMBER_CTOR
Bug: Method
OnlineLicenseDAOTest.testUpdateOnlineLicenseByOnlineMerchantId()
invokes inefficient Double.valueOf(double) constructor; use
OnlineLicenseDAOTest.java:[line 81] instead
Pattern id: DM_FP_NUMBER_CTOR, type: Bx, category: PERFORMANCE
Ddouble.valueOf
15. CN_IMPLEMENTS_CLONE_BUT_NOT_CLONEABLE
Cloneable
16. STCAL_INVOKE_ON_STATIC_DATE_FORMAT_INSTANCE
Bug: Call to method of static java.text.DateFormat
Pattern id: STCAL_INVOKE_ON_STATIC_DATE_FORMAT_INSTANCE, type: STCAL, category:
MT_CORRECTNESS
vector
Sun Bug #6231579 Sun Bug #6178997
DateFormatSimpleDateFormatCalendar
java private
vector
DateFormat sun
17. SE_NO_SERIALVERSIONID
Serializable serialVersionUID
serialVersionUID
1.
2.
JFrame
serialVersionUID
18.SE_COMPARATOR_SHOULD_BE_SERIALIZABLE
Serializable serialVersionUID
19. ES_COMPARING_STRINGS_WITH_EQ
Bug: Comparison of String objects using == or !=
Pattern id: ES_COMPARING_STRINGS_WITH_EQ, type: ES, category: BAD_PRACTICE
string
FX String s = new String("xyz");
String
equals
20. ES_COMPARING_STRINGS_WITH_EQ
propertyName ==
equals
21. IM_AVERAGE_COMPUTATION_COULD_OVERFLOW
Bug: Computation of average could overflow
Pattern id: IM_AVERAGE_COMPUTATION_COULD_OVERFLOW, type: IM, category: STYLE
22. SC_START_IN_CTOR
1. new <init>
JVM
2.
3. synchronized(:JLS 8.8.3 Constructor
Modifiers) synchronized
synchronized synchronized
<init>
new JVM
AsyncCentral FireThread AsyncCentral
AsyncCentral
FireThread AsyncCentral
AsyncCentral <init>
FireThread
AsyncCentral
Java.Concurrency.in.Practice
this FireThread this
this <init> FireThread
init
23. EQ_SELF_USE_OBJECT
ManageItem
Object boolean equals(Object)
@Override
JDK1.5 @Override JDK1.6
@Override
24.DLS_DEAD_LOCAL_STORE
By the way
class
eclipse Preferences
25.FE_TEST_IF_EQUAL_TO_NOT_A_NUMBER
Bug: Doomed test for equality to NaN
Pattern id: FE_TEST_IF_EQUAL_TO_NOT_A_NUMBER, type: FE, category: CORRECTNESS
Findbugs
Nan
x == Double.NaN false
x Double.isNaN(x)
26. FI_EMPTY
finalize
JDK finalize() Java JVM
finalize()
finalize
27.REC_CATCH_EXCEPTION
Bug: Exception is caught when Exception is not thrown
Pattern id: REC_CATCH_EXCEPTION, type: REC, category: STYLE
JVM RuntimeException
Exception EDT catch
(Exception e) RuntimeException
RuntimeException
28. DM_GC
Bug: DBExportTask2.exportDBRecords(DBExportProperty, String) forces garbage collection;
extremely dubious except in benchmarking code
Pattern id: DM_GC, type: Dm, category: PERFORMANCE
1. System.gc()JVM
2. System.gc() Full GC
GC Scavenge GC Full GCScavenge GC Eden
GCPerGen Eden
Scavenge GC GC Full GC Full GC
YoungTenured Perm Scavenge GC
Full GC
System.gc()
28. DP_DO_INSIDE_DO_PRIVILEGED
doPrivileged
30. MS_SHOULD_BE_FINAL
public get
final
31. NM_FIELD_NAMING_CONVENTION
Bug: The field name TopoControlPaneII.SyncSelection doesn't start with a lower case letter
Pattern id: NM_FIELD_NAMING_CONVENTION, type: Nm, category: BAD_PRACTICE
sun
Bug: Field only ever set to null: RaisecomStatus.infoURL
Pattern id: UWF_NULL_FIELD, type: UwF, category: CORRECTNESS
infoURL null
32. MS_PKGPROTECT
private
UserManager m_oThis = new UserManager();
Findbugs
protected private
33. FI_USELESS
finalize()
34. NP_NULL_ON_SOME_PATH
busCatId
35. NP_NULL_ON_SOME_PATH
This code creates an exception (or error) object, but doesn't do anything
with it. For example, something like
if (x < 0)
new IllegalArgumentException("x must be nonnegative");
if (x < 0)
throw new IllegalArgumentException("x must be nonnegative");
36. FI_FINALIZER_NULLS_FIELDS
finalize()
37. FI_PUBLIC_SHOULD_BE_PROTECTED
finalize()
38. IS2_INCONSISTENT_SYNC
Bug: Inconsistent synchronization of URLAlarmMonitor.m_Counter; locked 50% of time
Pattern id: IS2_INCONSISTENT_SYNC, type: IS, category: MT_CORRECTNESS
get set
39. LI_LAZY_INIT_UPDATE_STATIC
m_This protected 1
initMonitorRules 2 getInstance m_This
m_This 1 initMonitorRules
2
BUG
initMonitorRules
initMonitorRules
40. LI_LAZY_INIT_STATIC
bug 1 if 2 2
if a 1 1 b
happen-before DCL
41. WMI_WRONG_MAP_ITERATOR
42. BC_VACUOUS_INSTANCEOF
Bug: instanceof will always return true, since all TopoTreeNode are instances of TopoTreeNode
Pattern id: BC_VACUOUS_INSTANCEOF, type: BC, category: STYLE
instanceof
43. INT_BAD_REM_BY_1
I % 1 0I / 1 i
44. EI_EXPOSE_REP2
DO
values this.values
DO
DO Date gmtCrate
set gmtCreate
DO
public Date getGmtCreate() {
return new Date(this.gmtCreate.getTime()); //
}
45. EI_EXPOSE_REP
findBugs public
get
get
get
46. NP_NULL_PARAM_DEREF
queryScriptData
46. SBSC_USE_STRINGBUFFER_CONCATENATION
+ string java
StringBuffer StringBuilder
47. RV_RETURN_VALUE_IGNORED_BAD_PRACTICE
boolean
login int
0 1
use case
C
java checked Exception
java
File.delete
48. RV_RETURN_VALUE_IGNORED
S = s.trim
49. DM_BOOLEAN_CTOR
Bug: TopoCardManagerAction.processLocalCard(Hashtable) invokes inefficient Boolean
constructor; use Boolean.valueOf(...) instead
Pattern id: DM_BOOLEAN_CTOR, type: Dm, category: PERFORMANCE
50. RCN_REDUNDANT_NULLCHECK_OF_NULL_VALUE
Pattern id: RCN_REDUNDANT_NULLCHECK_OF_NULL_VALUE,
StringBuffer StringBuffer
51. DM_NUMBER_CTOR
bug
[Bx] Method invokes inefficient Number constructor; use static valueOf instead
[DM_NUMBER_CTOR]
[]http://www.cnblogs.com/hyddd/articles/1391318.html
FindBugs Integer.ValueOf(int) new Integer(int) int
-128127 Integer.ValueOf(int) Integer(int) 3.5
JDK Integer.ValueOf(int)
true
false
java Integer a = 100; -> Integer a = Integer.valueOf(100); a b
Cache c d c d
false