#957 No detection that a private field is never nulled

closed-wont-fix
5
2011-06-29
2011-06-29
Anonymous
No

In the attachement (which is a very contrived example, though inspired from a real world use-case), FindBugs complains about the line:
System.err.println(metrics.get(0));
iff the line above:
doSomething();
is not commented out.

This would be completely correct, when 'metrics' could toggle between non null and null.
However, I think that FindBugs would do a much better job at avoiding false positives if it could acknowledge that some private fields never go back to being null.

Thanks!

Discussion

  • Comment has been marked as spam. 
    Undo

    You can see all pending comments posted by this user  here

    Anonymous - 2011-06-29
     
  • William Pugh

    William Pugh - 2011-06-29

    The semantics of the CheckForNull annotation are that the value should be checked for null before being dereferenced every time it is loader.

    For example, the field might be changed via reflection or native methods. So the analysis can't be complete, and the annotation is trusted.

     
  • William Pugh

    William Pugh - 2011-06-29
    • assigned_to: nobody --> wpugh
    • status: open --> closed-wont-fix
     

Log in to post a comment.