![FindBugs在Eclipse中的應(yīng)用_第1頁](http://file3.renrendoc.com/fileroot_temp3/2021-12/21/cfdbd682-6c4a-4a75-8d97-0f326472585a/cfdbd682-6c4a-4a75-8d97-0f326472585a1.gif)
![FindBugs在Eclipse中的應(yīng)用_第2頁](http://file3.renrendoc.com/fileroot_temp3/2021-12/21/cfdbd682-6c4a-4a75-8d97-0f326472585a/cfdbd682-6c4a-4a75-8d97-0f326472585a2.gif)
![FindBugs在Eclipse中的應(yīng)用_第3頁](http://file3.renrendoc.com/fileroot_temp3/2021-12/21/cfdbd682-6c4a-4a75-8d97-0f326472585a/cfdbd682-6c4a-4a75-8d97-0f326472585a3.gif)
![FindBugs在Eclipse中的應(yīng)用_第4頁](http://file3.renrendoc.com/fileroot_temp3/2021-12/21/cfdbd682-6c4a-4a75-8d97-0f326472585a/cfdbd682-6c4a-4a75-8d97-0f326472585a4.gif)
下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、FindBugs在Eclipse中的應(yīng)用 作者:一路向北 更多信息請?jiān)L問我的百度空間: http:/ 浣花草堂 FindBugs在Eclipse中的應(yīng)用 路向北 本文介紹如何利用 Eclipse插件FindBugs在Eclipse中的使用。 Eclipse是目前非常流行的開發(fā)平臺,開放擴(kuò)展的架構(gòu)讓很多程序員找到了自己個(gè)性化 的工作環(huán)境。 問題提出: 當(dāng)我們編寫完代碼,做完單元測試等各種測試后就提交正式運(yùn)行, 只能由運(yùn)行的系統(tǒng)來 檢測我們代碼是否有問題了, 代碼中隱藏的錯(cuò)誤在系統(tǒng)運(yùn)行的過程中被發(fā)現(xiàn)后, 然后再來進(jìn) 行相應(yīng)的修改,那么后期修改的代價(jià)就相當(dāng)高了。 解決方法: 現(xiàn)在有很多Java代碼分
2、析工具,findbugs是一個(gè)開源的eclipse代碼檢查工具;它可以 簡單高效全面地幫助我們發(fā)現(xiàn)程序代碼中存在的 bug, bad smell,以及潛在隱患。針對各種 問題,它并且提供了簡單的修改意見供我們重構(gòu)時(shí)進(jìn)行參考; 通過使用它,可以一定程度 上降低我們code review的工作量,并且會提高review效率。 通過findbugs找到bug,再由 我們自己重構(gòu)代碼,可以培養(yǎng)我們的編碼意識及水平,形成好的習(xí)慣提高開發(fā)編碼能力。 安裝: JDK : JDK : 1.5.0 從 http:/ 上去下載安裝 EclipseEclipse: 3.1.1 從 http:/www.eclipse
3、.org 上去下載解壓 FindBugsFindBugs: 0.9.4 從 http:/ 官方的文檔: http:/ Eclipse plugin for FindBugs version 0.0.1Eclipse plugin for FindBugs version 0.0.17: http:/ 插件安裝: 網(wǎng)上有好多方法,不過我試驗(yàn)了,都不成功,我安裝成功的方法是直接發(fā)解壓后的文件 夾考到Eclipse plugin目錄下,然后重啟 Eclipse ,可以按以下步驟看到安裝是否成功: help about eclipse SDKy/plugin-details 能看到下圖紅線部分說明安裝
4、成功。 1FindBugs在Eclipse中的應(yīng)用 作者:一路向北 About lelipse Pltijg-insjnl xljnl xl Frevi der | FlHg-in Us, FMgrin TH Eclipse, org Plug-in Development Envir.- 3. 2,0. ir20060605 org. eclipse, pde r 皿 tin/ Eclipse, er & ENipt,工 E Eclipse. ar& Ecl i pt a. or( Eclipse, org Eclipse, srg Eclipca. “T
5、 Eclipse, org Eclipse, erg Eclipsa, Eclipse, org Eclipse. rg Ed ips 4. 4F; Eclipse, or g Eel ipse, or g Ellipse, or if Eclipse, org Flug-iii. Development UI V21 on Flu礦 in Befactoring Core Refa-ctoring LU Ssarch Support Standard Widget Toolki t Standard! Wi dgfet Tiiolki t f. T bb d Froperti as Vi A
6、W Team Support Core T ajti Support UI TiKt Text Editor FrameworlE Tomcat Tra.pper Vnivrsftl 冒尊 1牌麗 Vi ews Framewark Workbench Compatibility Findiui 3. 2.1. 20060. tfl!orp5rTn IBM Corporati oo Ine_ Inteiriiational Components . lore Info org. eclipse, pde ui or. aclipii ui : pra nil; tiiQxiI org. ecli
7、pse. Itk. core, re fact. org. edijhse. 1 tk ui refaetaring orf a. 5au*ch org. eclipse, swt ore. eelipa*. swt. Win32. Win32. 3. 2 1. R20060 . or. ui. viavs, proper. 3. 2.2. H20061114 org. eclipse, tean. core 3. 2. l.iZOftfiO. 3.2 0. w20060 3. 2.0.20060. 4. 1 130. v200.- 3.2 0.I20K0 3. 2.1.r321_v._ 3.
8、 2.2.r322_v. _ 3.2 1.R321 v. 3. 2.1.120060. 3. 2.2.R322 v . 3. 2,2. 200f70. 3. 2.0.120060.- org. eclipse, ua or. aclipe. IfiKt org. eclipse, ui. workbench, te.-. org. eclipse, tomcat 口 rg. aclipee. ui. intrQ. ijnivirsal org. eclipse, ui . vi ews org.白 cl ip白.ui . intro orf. eclipse, ui . workbench o
9、rg. ed i ps e. ui. orkb eich, co. - 1.常舌.zdUBi i 2 司虬 & 4: w:公日戰(zhàn)6里. jTTriTiUU&rZTJ cTTwracu 3.4 5.20051213 coa. ihm. icu. source 0i 1.26 CM. jcr if L jseh 本人極力推薦以下鏈接的文章,很好很值得一看。 http:/ 打不開也可在在 里面搜EclipseEclipse插件安裝 為了以后觀察方便先建立添加 findbugs explorer (eclipse 左下角) T LT? ci mi wep XUUK O al i s &
10、amp; fchannel &luc ene& ap i OK 百度文庫 Shov View 叫營 An t * AiptcO * Ciuwcltvi ty CVS 氣岐 n.g _ 雅 BL Ejqpl r r # ? Vf r AMi$4li W4 * W K*lp 功 it: XiVtrMlt * Jwv* trwiinc * q JFA * &m i Jr FDE RixatiH* Cucal EclipseEclipse里面使用findbug:findbug:創(chuàng)建簡單測試?yán)?2 更多信息請?jiān)L問我的百度空間: http:/ 浣花草堂 FindBugs在Ecli
11、pse中的應(yīng)用 作者:一路向北 更多信息請?jiān)L問我的百度空間: http:/ 浣花草堂 B閥 Explorer X L Problems 回后少希嬴膏TH _ lasMl ME M整 EI2 May expose internal represenlation by 粉中 V EI2: com. topsaft. findbugs. FindBugET 曰整El Miy expose iiUwrnU representati on by r 淬 中 V El: cam. topsoft. fiitdbugs. FindBugsTe! 可以看到黃色蟲子。找出的 bug蟲子顏色有三種:黑色的臭蟲標(biāo)志
12、是分類, 紅色的臭 蟲表示嚴(yán)重bug發(fā)現(xiàn)后必須修改代碼,橘黃色的臭蟲表示潛在警告性 bug盡量修。 Bug; D tulx Bohn&rks 1*5虹 Pr&crtsE JUnit (j 0 errcrs 2 0 infos Description | Resource | Fath | Location 登中 V EI2: con. top soft, findbucx. FindB FindBugsTest-. Findfiu iTtit/Erc/coA/t pE . FindBiafsrest/srcAcQ/tQps . 選中相應(yīng)的問題條目,右鍵,在彈出的菜單中,可以看到
13、 可以查看問題詳細(xì)信息,選中第一個(gè)問題描述如下: ShowBug Details ;選中也 3 首先,創(chuàng)建練習(xí)工程:FindBugsTest再創(chuàng)建測試類 FindBugsTest,代碼如下: package com.topsoft.findbugs; public class FindBugsTest private String name; public String getName() return name; public void setName(String口 name) this . name = name; 這個(gè)類里面有錯(cuò)誤,以便測試用。在編輯區(qū)里面點(diǎn)擊右鍵選擇 LOCnisio
14、ry r References * De cl ar atioits * 整Find Ruii As leLug As T 旦 am * Cgp覃e With ii th Clear Bug Markers Load XML 打開 Bugs ExploreFind Bugs Find Bugs B Tarnins itens) t 中 V EE coa. findbufK. FindBu FindBmiTtil. Bugs Explore右側(cè)Problems是問題信息,打開 Problems面板 Lint 7 line 11 FindBugs在Eclipse中的應(yīng)用 作者:一路向北 更多信息請
15、訪問我的百度空間: http:/ 浣花草堂 中 EI中 Priori ty Malieipus e&d-fr vulnerability In class co . t op soft findbugs. FindBngsTest In method com. top soft. i ndbogs. F i ndBugsT e s t getName 0 Fitld com. t-psoft, Eim.dbucs FindBufiTtxt. At FindBugsTest. j ava: line 7 中 y EI May expose interna】 representation
16、by refurniD reference to mutable object EI_EXPOSEJREP) Returning a reference to a mutable object kahie stored in one of the objects Helds exposes the internal representation of the object. If instances are accessed by untmsted code, and unchecked changes to the mutable object would compromise securi
17、ty or other important properties, von VhiH need to do something difierent. Returning a new copy of tht object is better approach in many situations. 根據(jù)這里詳細(xì)的信息,你可以得到 FindBugs為什么會對你的代碼報(bào)警告信息,及相應(yīng) 的處理辦法,根據(jù)它的提示,你可以快速方便地進(jìn)行代碼修改。 如果雙擊問題,系統(tǒng)會自動(dòng)跳轉(zhuǎn)到相對應(yīng)的問題行出。 根據(jù)提示,我們將代碼修改成如下,看看結(jié)果如何,剩余問題請諸位解決: package com.topsoft.
18、findbugs; public class FindBugsTest private String口 name; public String getName() String temp = name ; return temp; public void setName(String name) I String temp = name; this . name = temp; / / 配置 FindBugs:FindBugs: 在 Bugs Explorer 視圖中,選擇項(xiàng)目 右鍵 Properties FindBugs D Detector Configurationetector Con
19、figuration 在這里你可以選擇所要進(jìn)行檢查的相關(guān)的 Bug Pattern條目 可以從Bug codes、Detector name、Detector description中看到相應(yīng)的是要檢查哪些方面 的內(nèi)容,你可以根據(jù)需要選擇或去掉相應(yīng)的檢查條件。 Run FindBugs AutomaticallyRun FindBugs Automatically 當(dāng)此項(xiàng)選中后,F(xiàn)indBugs將會在你修改Java類時(shí)自動(dòng)運(yùn)行,如你設(shè)置了 Eclipse自動(dòng)編 譯開關(guān)后,當(dāng)你修改完 Java文件保存,F(xiàn)indBugs就會運(yùn)行,并將相應(yīng)的信息顯示出來。 當(dāng)此項(xiàng)沒有選中,你只能每次在需要的時(shí)候自己去運(yùn)行 FindBugs來檢查你的代碼。 4 Reporter Configuration Minimum priority to reportReporter Configuration Minimum priority to report Bug Details X Froblws Bookmarks Tasks Progress JVnit FindBugs在Eclipse中的應(yīng)用 作者:一路向北 更多信息請?jiān)L問我的百度空
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025-2030全球新能源電池CCS集成母排行業(yè)調(diào)研及趨勢分析報(bào)告
- 2025-2030全球無線藍(lán)牙肉類溫度計(jì)行業(yè)調(diào)研及趨勢分析報(bào)告
- 2025-2030全球血栓彈力圖檢測試劑盒行業(yè)調(diào)研及趨勢分析報(bào)告
- 2025-2030全球核電站管道系統(tǒng)行業(yè)調(diào)研及趨勢分析報(bào)告
- 2025-2030全球環(huán)氧干式變壓器行業(yè)調(diào)研及趨勢分析報(bào)告
- 2025年全球及中國超聲軟組織手術(shù)刀行業(yè)頭部企業(yè)市場占有率及排名調(diào)研報(bào)告
- 2025年全球及中國一次性3D儲液袋行業(yè)頭部企業(yè)市場占有率及排名調(diào)研報(bào)告
- 2025-2030全球聚氨酯泡沫開孔劑行業(yè)調(diào)研及趨勢分析報(bào)告
- 2025年全球及中國家具彈性帶行業(yè)頭部企業(yè)市場占有率及排名調(diào)研報(bào)告
- 2025【合同范本】服裝專賣店加盟合同
- 2024年湖南高速鐵路職業(yè)技術(shù)學(xué)院高職單招數(shù)學(xué)歷年參考題庫含答案解析
- 上海鐵路局招聘筆試沖刺題2025
- 國旗班指揮刀訓(xùn)練動(dòng)作要領(lǐng)
- 春季安全開學(xué)第一課
- 植物芳香油的提取 植物有效成分的提取教學(xué)課件
- 肖像繪畫市場發(fā)展現(xiàn)狀調(diào)查及供需格局分析預(yù)測報(bào)告
- 2021-2022學(xué)年遼寧省重點(diǎn)高中協(xié)作校高一上學(xué)期期末語文試題
- 同等學(xué)力英語申碩考試詞匯(第六版大綱)電子版
- 墓地個(gè)人協(xié)議合同模板
- 2024年部編版初中語文各年級教師用書七年級(上冊)
- 中日合同范本
評論
0/150
提交評論