日本免费全黄少妇一区二区三区-高清无码一区二区三区四区-欧美中文字幕日韩在线观看-国产福利诱惑在线网站-国产中文字幕一区在线-亚洲欧美精品日韩一区-久久国产精品国产精品国产-国产精久久久久久一区二区三区-欧美亚洲国产精品久久久久

靜態(tài)分析工具Findbugs怎么用?

靜態(tài)分析工具Findbugs怎么用??我們來看看Findbugs使用說明
1 用途
【靜態(tài)分析工具Findbugs怎么用?】FindBugs 是一個java bytecode靜態(tài)分析工具,它可以幫助java工程師提高代碼質(zhì)量以及排除隱含的缺陷 。
FindBugs檢查類或者 JAR 文件,將字節(jié)碼與一組缺陷模式進行對比以發(fā)現(xiàn)可能的問題 。
有了靜態(tài)分析工具,就可以在不實際運行程序的情況對軟件進行分析 。FindBugs不是通過分析類文件的形式或結(jié)構(gòu)來確定程序的意圖,而是通常使用 Visitor 模式進行分析(Visitor 模式的更多信息) 。
2 安裝
目前findbugs新的版本是1.3.9,
2.1 Eclipse插件的安裝
環(huán)境要求,F(xiàn)indbugs要求Eclipse 3.4 以上的版本,JRE/JDK 1.5.0以上的版本 。
步驟,將edu.umd.cs.findbugs.plugin.eclipse_1.3.9.20090821.zip解壓到Eclipse的 "plugins"子目錄下,這樣就可以在 /plugins/edu.umd.cs.findbugs.plugin.eclipse_1.3.9.20090821/下看到FindBugs logo圖片findbugs.png 。
啟動Eclipse 然后選擇 Help → About Eclipse Platform → Plug-in Details,你應(yīng)該找到 "FindBugs Plug-in" 。
3 使用
啟動
選中java工程,點擊鼠標右鍵,選擇名為“Find Bugs”的菜單,F(xiàn)indBugs開始運行,問題指示器將指向根據(jù)bug模式識別出來的潛在問題代碼位置 。

靜態(tài)分析工具Findbugs怎么用?



靜態(tài)分析工具Findbugs怎么用?


可選項定制
你還可以通過java工程的屬性對話框來定制findbugs的運行方式,可選項包括:
控制"Run FindBugs Automatically" 開關(guān)的checkbox 。選中時, FindBugs 將在每次修改java類后啟動運行 。
選擇最小告警優(yōu)先級和Bug類別 。這些選項將選擇哪些警告被顯示 。例如,如果你選擇"Medium",只有Medium 和 High priority 警告將被顯示 。近似地,如果你未選中 "Style" checkbox,Style類的警告信息將不會被顯示 。
選擇探測器 。這個列表允許你選擇你想在工程中使用的探測器 。
靜態(tài)分析工具Findbugs怎么用?


4 配套的Bug模式解釋
為了有針對性的使用這個工具,減少bug的誤報,提高使用效率,我們選擇了10個左右的bug模式,下面就是對這10個模式的解釋 。
這些bug可能會引起程序的性能或邏輯問題.
需要說明的是,findbugs能檢測的bug pattern遠不僅于此,甚至可以定制自己的探測器,因此,這個文檔會不斷擴充,同時,也歡迎大家不斷探索和分享使用實踐.
4.1 ES_COMPARING_PARAMETER_STRING_WITH_EQ
ES: Comparison of String parameter using == or != (ES_COMPARING_PARAMETER_STRING_WITH_EQ)
This code compares a java.lang.String parameter for reference equality using the == or != operators. Requiring callers to pass only String constants or interned strings to a method is unnecessarily fragile, and rarely leads to measurable performance gains. Consider using the equals(Object) method instead.
使用 == 或者 != 來比較字符串或interned字符串,不會獲得顯著的性能提升,同時并不可靠,請考慮使用equals()方法 。
4.2 HE_EQUALS_NO_HASHCODE
HE: Class defines equals() but not hashCode() (HE_EQUALS_NO_HASHCODE)
This class overrides equals(Object), but does not override hashCode(). Therefore, the class may violate the invariant that equal objects must have equal hashcodes.
類定義了equals()方法但沒有重寫hashCode()方法,這樣違背了相同對象必須具有相同的hashcodes的原則
4.3 IT_NO_SUCH_ELEMENT
It: Iterator next() method can't throw NoSuchElement exception (IT_NO_SUCH_ELEMENT)
This class implements the java.util.Iterator interface. However, its next() method is not capable of throwing java.util.NoSuchElementException. The next() method should be changed so it throws NoSuchElementException if is called when there are no more elements to return.

推薦閱讀