1. 程式人生 > >FindBugs-IDEA外掛的安裝和使用

FindBugs-IDEA外掛的安裝和使用

1.下載
因為使用idea線上無法下載,可下載這個連結的外掛,親測可用
https://download.csdn.net/download/libra_ts/10467779
2.安裝
這裡寫圖片描述
這裡寫圖片描述
這裡寫圖片描述
安裝完成,重啟。

3.使用
a.這裡寫圖片描述
這裡寫圖片描述

Bad practice程式碼中的一些壞習慣

Class names should start with an upper case letter 主要包括類名的命名,以大寫字母開頭
Method names should start with a lower case letter 方法名以小寫字母開頭
Field names should start with a lower case letter 欄位名以小寫字母開頭
equals()method does not check for null argument equals()方法應該檢查非空
Class defines equals() and uses Object.hashCode() 一個類覆寫了equals方法,沒有覆寫hashCode方法,使用了Object物件的hashCode方法
Method ignores exceptional return value 方法忽略返回值的異常資訊
Equals method should not assume anything about the type of its argument equals(Object o)方法不能對引數o的型別做任何的假設。比較此物件與指定的物件。當且僅當該引數不為 null,並且是表示與此物件相同的型別的物件時,結果才為 true。
Comparison of String objects using == or != 用==或者!=去比較String型別的物件
Method might ignore exception 方法可能忽略異常
Method invokes System.exit() 在方法中呼叫System.exit(…)語句,考慮用RuntimeException來代替
Method ignores result of InputStream.read() InputStream.read方法忽略返回的多個字元,如果對結果沒有檢查就沒法正確處理使用者讀取少量字元請求的情況。
Dodgy code 糟糕的程式碼

Switch statement found where default case is missing Switch沒有預設情況下執行的case語句
Switch statement found where one case falls through to the next case Switch語句中一個分支執行後又執行了下一個分支。通常case後面要跟break 或者return語句來跳出。
Dead store to local variable 該指令為區域性變數賦值,但在其後的沒有對她做任何使用。通常,這表明一個錯誤,因為值從未使用過。
Write to static field from instance method 在例項方法寫入靜態欄位
Redundant nullcheck of value known to be non-null 方法中對不為空的值進行為空的判斷。
Method uses the same code for two branches 此方法使用相同的程式碼,以實現兩個有條件的分支。檢查以確保這是不是一個編碼錯誤
Exception is caught when Exception is not thrown 在try/catch塊中捕獲異常,但是異常沒有在try語句中丟擲而RuntimeException又沒有明確的被捕獲
Integral division result cast to double or float 整形數除法強制轉換為double或者float型別。
Possible null pointer dereference due to return value of called method 方法的返回值沒有進行是否為空的檢查就重新賦值,這樣可能會出現空指標異常。
Useless object created 物件建立了並沒有用
Unread public/protected field 沒有用到的欄位
Internationalization 關於程式碼國際化相關方面的

Consider using Locale parameterized version of invoked method
使用平臺預設的編碼格式對字串進行大小寫轉換,這可能導致國際字元的轉換不當。使用以下方式對字元進行轉換
Performance 關於程式碼效能相關方面的

Boxing/unboxing to parse a primitive 型別轉換 比如字串轉換成int 應該使用Integer.parseInt(“”) 代替Integer.valueOf(“”)
Method concatenates string using + in aloop
每次迴圈裡的字串+連線,都會新產生一個string物件,在java中,新建一個物件的代價是很昂貴的,特別是在迴圈語句中,效率較低
解決辦法:使用StringBuffer或者StringBuilder重用物件。
Private method is never called 私有方法沒有被呼叫
Explicit garbage collection;extremely dubious except in benchmarking code
在程式碼中顯式的呼叫垃圾回收命名,這樣做並不能起作用。在過去,有人在關閉操作或者finalize方法中呼叫垃圾回收方法導致了很多的效能浪費。這樣大規模回收物件時會造成處理器執行緩慢。
Unread field:should this field be static? 沒有用到的static 欄位
should be a static inner class 此內部類應該使用static修飾
Experimental

Method may fail to clean up stream or resource on checked exception
這種方法可能無法清除(關閉,處置)一個流,資料庫物件,或其他資源需要一個明確的清理行動
解決方法:流的關閉都寫在finally裡面
Malicious code vulnerability 關於惡意破壞程式碼相關方面的

May expose internal representation by incorporating reference to mutable object
此程式碼把外部可變物件引用儲存到物件的內部表示。如果例項受到不信任的程式碼的訪問和沒有檢查的變化危及物件和重要屬性的安全。儲存一個物件的副本,在很多情況下是更好的辦法。
Field isn’t final but should be 此欄位前應該加final
Field isn’t final and can’t be protected from malicious code 此欄位前應該加final
Field should be package protected
一個靜態欄位是可以被惡意程式碼或其他的包訪問修改。可以把這種型別的欄位宣告為final型別的以防止這種錯誤。
Multithreaded correctness 關於程式碼正確性相關方面的

Static DateFormat DateFormat 在多執行緒中本身就是不安全的,如果線上程範圍中共享一個DateFormat的例項而不使用一個同步的方法在應用中就會出現一些奇怪的行為。
Call to static DateFormat DateFormats多執行緒使用本事就是不安全的,改進方法:需要建立多例項或執行緒同步
Correctness 關於程式碼正確性相關方面的

Nullcheck of value previously dereferenced 此程式碼之前廢棄null值檢查。解決辦法 進行null檢查
Possible null pointer dereference 可能為null
Null pointer dereference 物件賦為null值後 沒有被重新賦值
Possible null pointer dereference in method on exception path 在異常null值處理分支呼叫的方法上,可能存在物件去除引用操作
value is null and guaranteed to be dereferenced on exception path exception分支上,存在引用一個null物件的方法,引發空指標異常。
Self comparison of value with itself 方法中對一個區域性變數自身進行比較運算,並可說明錯誤或邏輯錯誤。請確保您是比較正確的事情。
An apparent infinite recursive loop 明顯的無限迭代迴圈,將導致堆疊溢位.