FindBugs bug类型说明

Findbugs是一个静态分析工具,它检查类或者JAR 文件,将字节码与一组缺陷模式进行对比以发现可能的问题。Findbugs自带检测器,其中有60余种Bad practice,80余种Correctness,1种 Internationalization,12种Malicious code vulnerability,27种Multithreaded correctness,23种Performance,43种Dodgy。

一、Bug级别

根据Bug可能导致的后果,FindBugs定义了若干Bug级别,主要的级别如下所示:

Bad Practice: 不好的实践

Correctness: 正确性

Experimental:试验性的

Internationalization:   国际化的

Malicious code vulnerability: 存在漏洞的有害代码

Multithreaded correctness: 多线程正确性

Performance:性能

Security:安全

Dodgy: 欺骗性代码

二、常见bug及处理方法

http://wenku.baidu.com/link?url=kEfgjhK2h1Lghe0hkkpPsw4VCpHFLMI16nwPJiTw1QU_BfjhKDH5oeAcmhn5KD53_WpOs3Z5LwTUfvmqGFSXg1D1DKJhvAJEefrscRPjxoq

http://wenku.baidu.com/link?url=dluPWnkv3bINtb0ndbf_9qwpGsvsZxlpDHzWFRC8_oDI7G5pRUg2-K83TGPI93HQ8kb7cvIdVt-CunOhTC22AtCqRAVEDmHoM26K2msgQ9a

FindBugs插件设置说明

来源网址:file:///C:/Users/niupp/AppData/Local/Yodao/DeskDict/frame/20141120132153/index.html#

1、打开设置界面:项目>属性>FindBugs

Enable project specific settings:使能项目的个性化设置;

Run automatically(also on full build):自动运行(编译工程和文件的时候自动运行);

analysis effort:分析工作,选择Minimal速度最快但不够准确;

Store issue evaluation in:问题评价的存储,应该是选择是否将问题上传到FindBugs Cloud上;

Reporter Configuration:报告设置;

Minimunm rank to report:等级报告,选择某数字表示报告该数字以上等级bug,1表示最严重,20最轻微;

Minimunm Confidence to report:选择Low,Low以上级别都会显示,即所有级别的提示信息都会被显示;

Reported(visible )bug categories:报告(可见)的bug种类,选择相关种类后,该类型的bug才会显示;

Bad Practice: 不好的实践;

Malicious code vulnerability: 存在漏洞的有害代码;

Correctness: 正确性;

Performance:性能;

Security:安全;

Dodgy code: 欺骗性代码;

Experimental:试验性的;

Multithreaded correctness: 多线程正确性;

Internationalization: 国际化的;

Mark bugs with…rank as:标记bug的等级;

Filter files:过滤文件,包括或者排除特定的类和方法的bug检测,将过去的XML的FindBugs结果报告添加后可以将报告中的bug排除分析;

Plugins and misc.Settings:插件和misc的设置;

Run FB analysis as extra job(independent from build job):运行FB分析作为额外的工作(独立于构建工作),可以改进用户体验特别是对于递增编译;

Cache .class data(useful for slow file system & lot of RAM)(experimental):类文件的缓存数据,为下一次的FindBugs分析可以重用该缓存数据,缓存会一直保持知道下一次项目的构建;

Currently, plugins can only be updated from the workspace settings:现在,插件只能通过工作区的设置来升级;

Detector configuration:检测器配置,可以选择所要进行检查的相关的Bug 模式条目,不勾选的检测器将不会在进行分析,“Grayed out”的检测器会运行但是不会输出报告到界面;

2、检测器类型

http://wenku.baidu.com/link?url=u37YN6F58LkqIsPwcaQJ1RPN-4khSqzTQt9tvydRZO-kn1Me4VY2jzub6OsmxzXXBDoQVN4IqxnTr74d2GGTPTrdS-zuVBLlaYvjbLDBukG

AppendingToAnObjectOutputStream:添加到一个对象的输出流;

AtomicityProblem:并发抽象上的操作序列(如get / put)将不会自动执行;

BadAppletConstructor:坏的Applet构造函数;

BadResultSetAccess:寻找getXXX或setXXX方法调用的结果集字段索引为0,但实际结果集字段索引从1开始;

BadSyntaxForRegularExpression:正则表达式的无效语法;

BadUseOfReturnValue:坏的返回值使用,在非空检查之后函数的返回值被丢弃;

BadlyOverriddenAdapter:严重覆盖适配器,该代码使用错误的签名扩展了一个适配器类,覆盖了一个监听器方法;

BooleanReturnNull:布尔类型返回空值;

CallToUnsupportedMethod:调用不支持的方法;

CheckExpectedWarnings:检查预期警告;

CheckImmutableAnnotation:检查不变的注释;

CheckRelaxingNullnessAnnotation:传给方法一个声明为@NonNull的null参数;方法的返回值声明为@NonNull实际是null。

CheckTypeQualifiers:检查类型修饰符;

CloneIdiom:查找违反编写可克隆类的习语;

ComparatorIdiom:比较器;

ConfusedInheritance:混乱的继承;

ConfusionBetweenInheritedAndOuterMethod: 混淆继承和外部方法;

CrossSiteScripting:寻找明显的跨站脚本漏洞;

DefaultEncodingDetector:默认编码检测器,当对字符串使用upper或lowercase方法,如果是国际的字符串,可能会不恰当的转换。

DoInsideDoPrivileged:寻找doPrivileged内应该执行的代码块;

DontCatchIllegalMonitorStateException:查找try - catch块的非法监控状态异常;

DontIgnoreResultOfPutIfAbsent:不要忽视PutIfAbsent的结果;

DontUseEnum:不使用枚举;

DroppedException:DE查找代码中,捕获了异常,但不采取措施来处理异常的情况;

DumbMethodInvocations:愚蠢的方法调用;

DumbMethods:愚蠢的方法;

DuplicateBranches:查找如 if/else or switch的重复分支;

EmptyZipFileEntry:空的zip文件;

EqualsOperandShouldHaveClassCompatibleWithThis:不兼容的类定义equals方法;

ExplicitSerialization:明确的序列化;

FinalizerNullsFields:终结器null字段;

FindBadCast2:查找坏了使用数据流分析的对象引用;

FindBadForLoop:查找不正确的循环;

FindCircularDependencies:查找类间的循环依赖;

FindDeadLocalStores:查找无用的局部变量存储;

FindDoubleCheck:查找双重检查锁定;

FindEmptySynchronizedBlock:检查孔的同步块;

FindFieldSelfAssignment:

FindFinalizeInvocations:查找调用finalize()或与此相关的问题;

FindFloatEquality:

FindHEmismatch:

FindInconsistentSync2:

FindJSR166LockMonitorenter:

FindLocalSelfAssignment2:

FindMaskedFields:

FindMismatchedWaitOrNotify:

FindNakedNotify:

FindNonShortCircuit:

FindNullDeref:

FindNullDerefsInvolvingNonShortCircuitEvaluation:

FindOpenStream:

FindPuzzlers:

FindRefComparison:

FindReturnRef:

FindRoughConstants:

FindRunInvocations:

FindSelfComparison:

FindSelfComparison2:

FindSleepWithLockHeld:

FindSpinLoop:

FindSqlInjection:

FindTwoLockWait:

FindUncalledPrivateMethods:

FindUnconditionalWait:

FindUninitializedGet:

FindUnrelatedTypesInGenericContainer:

FindUnreleasedLock:

FindUnsatisfiedObligation:

FindUnsyncGet:

FindUseOfNonSerializableValue:

FindUselessControlFlow:

FormatStringChecker:

HugeSharedStringConstants:

IDivResultCastToDouble:

FindBugs bug代码举例

一、不需要修改的Bug

1、源代码

privateString[]name;

publicString[] getName(){

returnname;

}

2、Bug描述

Bug: Findbugs.getName() may expose internal representation by returning name

Returning a reference to a mutable object value stored in one of the object’s fields exposes the internal representation of the object.  If instances are accessed by untrusted code, and unchecked changes to the mutable object would compromise security or other important properties, you will need to do something different. Returning a new copy of the object is better approach in many situations.

Rank: Of Concern (18),confidence: Normal

Pattern: EI_EXPOSE_REP

Type: EI,Category: MALICIOUS_CODE (Malicious code vulnerability)  存在漏洞的有害代码

说明:Bug: Findbugs.getName()可能会因为返回值暴露内部存储对象地址。

调用get和set方法,修改对象属性,被修改的对象属性是一个可变的对象。

3、修改后代码

privateString[]name;

publicString[] getName() {

String[] temp =name;

returntemp;

}

二、需要处理的Bug

1、源代码

publicvoidtest(){

String abc =“abc”;

String xyz =newString("");

xyz = abc;

System.out.println(xyz);

}

2、Bug描述

Bug: Dead store to xyz in Findbugs.test()

This instruction assigns a value to a local variable, but the value is not read or used in any subsequent instruction. Often, this indicates an error, because the value computed is never used.

Note that Sun’s javac compiler often generates dead stores for final local variables. Because FindBugs is a bytecode-based tool, there is no easy way to eliminate these false positives.

Rank: Of Concern (17),confidence: Normal

Pattern: DLS_DEAD_LOCAL_STORE

Type: DLS,Category: STYLE (Dodgy code)   欺骗性代码

说明:Bug:对变量xyz赋值

对局部变量赋值,但是这个变量没有在后续的代码中没有使用。

确认该局部变量未使用,可去掉。

Bug: Findbugs.test() invokes inefficient new String(String) constructor

Using thejava.lang.String(String)constructor wastes memory because the object so constructed will be functionally indistinguishable from theStringpassed as a parameter.  Just use the argumentStringdirectly.

Rank: Of Concern (18),confidence: Normal

Pattern: DM_STRING_CTOR

Type: Dm,Category: PERFORMANCE (Performance)  性能

说明:Bug:使用String(String)构造使效率低下

使用java.lang.String(String)构造浪费了内存,因为对象构造字符串作为参数传递与直接使用参数字符串功能上没有区别。

3、修改后代码

publicvoidtest(){

String abc =“abc”;

//Stringxyz= new String("");

String xyz = abc;

System.out.println(xyz);

}

1、源代码

publicvoidtest(){

String str =“123”;

if(str!=null){

System.out.println(str);

}

}

2、Bug描述

Bug: Redundant nullcheck of str, which is known to be non-null in Findbugs.test()

This method contains a redundant check of a known non-null value against the constant null.

Rank: Of Concern (18),confidence: Normal

Pattern: RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE

Type: RCN,Category: STYLE (Dodgy code)   欺骗性代码

说明:Bug: 多余的非空检查,在Findbugs.test()已知是非空

没有必要进行if判断

3、修改后代码

publicvoidtest(){

Stringstr=“123”;

System.out.println(str);

}

1、Bug描述

Bug: The class name findbugs doesn’t start with an upper case letter

Class names should be nouns, in mixed case with the first letter of each internal word capitalized. Try to keep your class names simple and descriptive. Use whole words-avoid acronyms and abbreviations (unless the abbreviation is much more widely used than the long form, such as URL or HTML).

Rank: Of Concern (16),confidence: Normal

Pattern: NM_CLASS_NAMING_CONVENTION

Type: Nm,Category: BAD_PRACTICE (Bad practice)  不好的实践

说明:类名findbugs首字母没有大写

Java中类的名称首字母需要大写

FindBugs的使用方法

来源网址:http://findbugs.sourceforge.net/downloads.html

FindBugs下载地址:http://findbugs.sourceforge.net/downloads.html

方法一:图形界面

1、下载 FindBugs tool,打开bin目录下的FindBugs.bat文件(需要在JAVA环境下),FindBugs图形界面如下:

2、点击文件>新建,输入需要检测的项目信息即可。

方法二:Eclipse插件

1、在Eclipse中安装好插件后,选择需要检测的项目,右击Find bugs

FindBugs在Eclipse中的安装

来源网址:http://findbugs.cs.umd.edu/eclipse/

方法一:下载插件安装

1、插件下载路径:http://findbugs.sourceforge.net/downloads.html

2、下载插件解压缩后,将插件复制到Eclipse的plugins文件夹下,重启Eclipse即可

3、查看是否安装成功:打开Eclipse的Help>Installation Details>Plug-ins

方法二:线上安装

1、方法参考:http://findbugs.cs.umd.edu/eclipse/

2、打开Eclipse的Help>Install New Software…界面,点击add按钮,输入Name为FindBugs,Location为http://findbugs.cs.umd.edu/eclipse,

作者:仲丽萍
链接:https://www.jianshu.com/p/9740c94c489d
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

转载自请点这里

FindBugs配置介绍相关推荐

  1. Centos 7 冗余备份磁盘配置介绍

    Centos 7 冗余备份磁盘配置介绍 我们上一盘介绍了Centos 7 磁盘阵列配置介绍,今天继续上一篇的配置介绍,通过上一篇的配置介绍我们发现了一个问题.,运维人员需要在硬盘硬件出现故障后,手动增 ...

  2. iphonex重量_精仿苹果iPhone X手机配置介绍

    精仿苹果iPhone X手机配置介绍 [上市时间] 2017年10月最新版 [屏幕色彩] 1600万 [分 辨 率] 1920X1080 [屏幕尺寸] 5.8英寸IPS全视角电容式触摸屏 [处 理 器 ...

  3. SQL Server 2016 AlwaysOn 安装及配置介绍

    SQL Server 2016  AlwaysOn 安装及配置介绍 Always On 可用性组功能是一个提供替代数据库镜像的企业级方案的高可用性和灾难恢复解决方案. SQL Server 2012 ...

  4. 最新架构amd服务器cpu,AMD Zen架构处理器全新性能配置介绍

    AMD CEO日前在台北电脑展上首次展示了一颗基于Zen全新架构的下代处理器,这也是我们第一次看到其真身,下面就详情来看看了解下吧! AMD处理器常年被Intel压制,尤其是在服务器上已经基本没有存在 ...

  5. Window VNC远程控制LINUX:VNC详细配置介绍

    Window VNC远程控制LINUX:VNC详细配置介绍 //---------------------------------------vnc linux下的详细配置 1.VNC的启动/停止/重 ...

  6. Tsung MQTT协议简介及MQTT xml文档配置介绍

    MQTT协议简介及MQTT xml文档配置介绍 by:授客 QQ:1033553122 1. MQTT协议介绍 MQTT(Message Queuing Telemetry Transport,消息队 ...

  7. 鸟哥的Linux私房菜(基础篇)- 第二十四章、 X Window 配置介绍

    第二十四章. X Window 配置介绍 最近升级日期:2009/08/07 在 Linux 上头的图形介面我们称之为 X Window System,简称为 X 或 X11 罗!为何称之为系统呢?这 ...

  8. n3k配置vpc是否还需要配置hsrp_VPC配置介绍

    VPC(Virtual Port-Channel)是Cisco Nexus系列交换机中的一个特性.它支持一个跨机箱的二层Port-Channel.对于第三方设备来说(交换机或服务器)物理上是连接到了两 ...

  9. LINUX服务器搭建和常用配置介绍

    服务器搭建 : 搭建私有CA服务器 : http://www.cnblogs.com/zhaojiedi1992/p/zhaojiedi_linux_011_ca.html 搭建samba服务器 : ...

最新文章

  1. 基于pytorch的卷积神经网络量化实现
  2. Java 基本类型相互转换
  3. STL 之search,search_n,sort,binary_search
  4. Quartz Scheduler插件–隐藏的宝藏
  5. CouchDB未授权访问漏洞记录(端口:5984、6984,CVE-2017-12635,CVE-2017-12636)复现失败
  6. http://ftp.gnu.org/gnu/ http://ftp.gnu.org/gnu/libc/
  7. python界面开发 web_使用 web 技术构建 python 的 GUI 界面
  8. 都说做作设计要多看多参考,那哪里才能找到优秀原创设计作品?
  9. 1188 最大公约数之和 V2
  10. 信息系统项目管理师(高项)考试的论文怎么写,怎么背?经验分享
  11. 计算机常出现的问题及解决办法,电脑发生故障的常见现象和解决方法
  12. 打苹果,诉三星……陌生的它,是中国乃至全球最神秘科技公司
  13. 开源MySQL数据仓库解决方案:Infobright
  14. 转载收藏 常用数学符号的读法及其含义
  15. css的3种布局方式
  16. C++ 链表的基本操作
  17. windows10的几个常用快捷键
  18. TypeScript基础教程
  19. 联想收购IBM个人电脑业务
  20. 机械制图及计算机绘图试题库,机械制图及计算机绘图试题库(下).doc

热门文章

  1. Qt商业组件QtitanRibbon:致力于现代化Office界面开发
  2. 密码学03--go语言与非对称加密RSA算法的实现
  3. GEE学习——用公式写SAVI/NDVI指数!
  4. mysql双机热备_mysql双机热备实现方案
  5. 对安全研究人员和渗透测试人员有用的Firefox 插件
  6. 扫个二维码微信就崩溃的原因找到了|附源码分析
  7. 员工绩效评估的目的是什么?
  8. 欢聚时代面试——感受
  9. squid 中文权威指南--第5章 Squid运行
  10. java与c语言的优劣势_C语言和Java的优缺点