有没有办法让 FindBugs 检查并警告我,如果 CheckForNull 注释出现在类中的方法的实现上,而不是在接口中的方法声明上?
import javax.annotation.CheckForNull;
interface Foo {
public String getBar();
}
class FooImpl implements Foo {
@CheckForNull
@Override
public String getBar() {
return null;
}
}
public class FindBugsDemo {
public static void main(String[] args) {
Foo foo = new FooImpl();
System.out.println(foo.getBar().length());
}
}
我刚刚在我的应用程序中发现了一个错误,因为 FindBugs 没有发现缺少空检查,因为 CheckForNull 仅存在于 FooImpl 上,但不存在于 Foo 上,我不想手动发现此问题的所有其他位置。