【发布时间】:2010-03-10 09:39:22
【问题描述】:
如果在类中方法的实现中存在 CheckForNull 注解,但在接口中的方法声明中没有,是否有任何方法可以让 FindBugs 检查并警告我?
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 上,我不想发现此问题的所有其他位置手动。
【问题讨论】:
标签: java class interface findbugs