Section 3.7.2 of the Checker Reference Manual
解释这种(不受欢迎的)行为:
3.7.2
关于findbugs@nullable的不兼容说明
findbugs的非标准定义为@nullable。芬布斯
治疗没有记录在自己的javadoc中;它不同于
在其他用于空度分析的工具中定义@nullable;
当应用于一个正式的
参数;它总是让程序员吃惊。因此,FindBugss
@nullable作为文档是有害的,而不是有用的。在
练习,你最好不要依赖findbugs来获得空值。
分析,即使您发现findbugs对其他用途有用…
findbugs禁止使用@nullable变量时出现所有警告。(你
必须使用@checkfornull来指示一个可以为空的变量,
findbugs应该检查。)…
// declare getObject() to possibly return null
@Nullable Object getObject() { ... }
void myMethod() {
@Nullable Object o = getObject();
// FindBugs issues no warning about calling toString on a possibly-null reference!
o.toString();
}
…使用findbugs,可以注释一个声明,该声明禁止检查
在所有客户机使用的地方,甚至是您想要检查的地方。