Why is FindBugs ignoring my check for null?

馋奶兔 提交于 2019-12-22 04:38:12

问题


Can anyone explain me why this throws a findbug warning:

if (m != null && m.getModifiedDate() != null)
    content.put("ModifiedDate", m.getModifiedDate().getTime());

and this is working:

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.

Is there a possibilty to tell FindBugs that Example number 1 should not be a warning?


回答1:


Possibly because m.getModifiedDate() could return a non-null value on the first call, but a null value on the second?



来源:https://stackoverflow.com/questions/9836208/why-is-findbugs-ignoring-my-check-for-null

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!