Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is FindBugs ignoring my check for null?

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?

like image 719
soulcinder Avatar asked Mar 23 '12 08:03

soulcinder


1 Answers

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

like image 104
Jon Skeet Avatar answered Oct 05 '22 20:10

Jon Skeet