FindBugs 是一个静态分析工具,它检查类或者 JAR 文件,将字节码与一组缺陷模式进行对比以发现可能的问题。有了静态分析工具,就可以在不实际运行程序的情况对软件进行分析。不是通过分析类文件的形式或结构来确定程序的意图,而是通常使用 Visitor 模式
1. eclipse插件安装 http://findbugs.cs.umd.edu/eclipse-daily/
2. 使用
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)
改正:
} else if (existingTestCase.getStatus().getStatusID().equals(DataStatusEnum.DELETE.getValue())) {