关于findbugs检测空指针判断

来源:互联网 发布:淘宝拍下显示系统错误 编辑:程序博客网 时间:2024/06/01 10:03

使用findbugs检测代码时,会出现NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE空指针警告提示,即使加入null判断还是出现次警告。例如:

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());}

可能原因是:

m.getModifiedDate()第一次不为空,但是第二次有可能为空。

0 0
原创粉丝点击