從 FingBugs的錯誤來看JAVA代碼質量(四)

[b]錯誤碼:RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE[/b]


[img]http://dl.iteye.com/upload/attachment/511818/d309c0e6-d1d2-35d1-9e01-093748dc45fe.jpg[/img]

Bug: Redundant nullcheck of bean1, which is known to be non-null
Pattern id: RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE, type: RCN, category: STYLE
This method contains a redundant check of a known non-null value against the constant null.
解釋:這種方法包含了一個稱爲非空對空值的不斷重複檢查。
修改爲:


[img]http://dl.iteye.com/upload/attachment/511820/8644fd8c-1e2d-3f90-99b6-4aef922af903.jpg[/img]


[b]錯誤碼:SS_SHOULD_BE_STATIC[/b]


[img]http://dl.iteye.com/upload/attachment/511822/d62f4cf0-bed3-3181-865f-95c8e652cf68.jpg[/img]

Bug: Unread field: ADDRESS_KEY; should this field be static?
Pattern id: SS_SHOULD_BE_STATIC, type: SS, category: PERFORMANCE
This class contains an instance final field that is initialized to a compile-time static value. Consider making the field static.
解釋:
final成員變量表示常量,只能被賦值一次,賦值後值不再改變。
這個類包含的一個final變量初始化爲編譯時靜態值。考慮變成靜態常量
解決方法:
增加static關鍵字


[b]錯誤碼:NM_METHOD_NAMING_CONVENTION[/b]

[img]http://dl.iteye.com/upload/attachment/511825/69b8122f-e464-35b9-a5fd-c3e59320d3ae.jpg[/img]

Bug: The method name MsmPlanDAOTest.TestViewMsmPlanList() doesn't start with a lower case letter
Pattern id: NM_METHOD_NAMING_CONVENTION, type: Nm, category: BAD_PRACTICE
Methods should be verbs, in mixed case with the first letter lowercase, with the first letter of each internal word capitalized.
解釋:
方法應該是動詞,與第一個字母小寫混合的情況下,與每個單詞的首字母大寫的內部。
解決方法:
方法名稱小寫就通過了。我們寫代碼還是要規範啊,雖然是單元測試的代碼!
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章