FindBugs用于找出代码的bug;
安装方法:进入Eclipse MarketPlace 查询FindBugs即可安装;
Perspective:FindBugs
View:Bug Explorer、Bug Info、Bug Reviews
Bug Explorer用来显示全部的错误概览;
Bug Info用来显示每个Bug的具体信息;
如果要使用FindBugs,只需要在源代码界面右击,找到 “Find Bugs” --> “Find Bugs” 即可;然后我们进入FindBugs Perspective即可;
下面的代码为例:
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
public class Test1 {
public static void main(String[] args) throws FileNotFoundException {
//1.未使用变量
InputStream in = new FileInputStream(args[0]);
//2.字符串比较Bug
String str1 = "abc";
String[] str = new String[]{"abc","cde"};
System.out.println(str1.equals(str));
}
}
在Bug Explorer中会出现找到的Bugs:
Bug Info中说明每个Bug的具体原因: