FindBugs

FindBugs 是一个静态分析工具,它检查类或者 JAR 文件,将字节码与一组缺陷模式进行对比以发现可能的问题。有了静态分析工具,就可以在不实际运行程序的情况对软件进行分析。不是通过分析类文件的形式或结构来确定程序的意图,而是通常使用 Visitor 模式

1. eclipse插件安装 http://findbugs.cs.umd.edu/eclipse-daily/


2. 使用

[img]http://dl2.iteye.com/upload/attachment/0090/8664/9e368f2f-5711-3fc4-9bee-1a7a97e44d73.jpg[/img]

[img]http://dl2.iteye.com/upload/attachment/0090/8666/bd7ea2d4-a5d7-30c4-957d-0f642f3f6e32.jpg[/img]

[img]http://dl2.iteye.com/upload/attachment/0090/8668/a2cf442f-eab9-3631-a597-8516c5fd731d.jpg[/img]

3. 例子

原始代码
else if (existingTestCase.getStatus().getStatusID() == DataStatusEnum.DELETE.getValue()) {

Findbugs报错

Bug: Suspicious comparison of Integer references in com.technicolor.utf.testdirectory.service.TestCaseService.syncFromCVS(TestCaseDto)

This method compares two reference values using the == or != operator, where the correct way to compare instances of this type is generally with the equals() method. It is possible to create distinct instances that are equal but do not compare as == since they are different objects. Examples of classes which should generally not be compared by reference are java.lang.Integer, java.lang.Float, etc.

Confidence: High, Rank: Scariest (1)
Pattern: RC_REF_COMPARISON
Type: RC, Category: CORRECTNESS (Correctness)

[img]http://dl2.iteye.com/upload/attachment/0090/8679/4c96a1e1-fa0d-3995-9137-c5208bd697d3.jpg[/img]


改正:

} else if (existingTestCase.getStatus().getStatusID().equals(DataStatusEnum.DELETE.getValue())) {
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值