为什么FindBugs忽略我对null的检查? [英] Why is FindBugs ignoring my check for null?
本文介绍了为什么FindBugs忽略我对null的检查?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
谁能向我解释为什么这会引发findbug警告:
Can anyone explain me why this throws a findbug warning:
if (m != null && m.getModifiedDate() != null)
content.put("ModifiedDate", m.getModifiedDate().getTime());
,这是可行的:
if(m != null){
Date date = m.getModifiedDate();
if (date != null)
content.put("ModifiedDate", date .getTime());
}
警告:由于调用方法的返回值,可能会取消引用空指针。
Warning: Possible null pointer dereference due to return value of called method.
是否可以告诉FindBugs示例1不应作为警告?
Is there a possibilty to tell FindBugs that Example number 1 should not be a warning?
推荐答案
可能是因为 m.getModifiedDate()
可能在第一次调用时返回非空值,但在第二次调用时返回空值吗?
Possibly because m.getModifiedDate()
could return a non-null value on the first call, but a null value on the second?
这篇关于为什么FindBugs忽略我对null的检查?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文