What is the meaning of Possible null pointer dereference in findbug?

Saeed Zarinfam picture Saeed Zarinfam · Sep 3, 2012 · Viewed 67.7k times · Source

I am using Sonar and I have got this kind of violation from it for a peace of my code:

 Correctness - Possible null pointer dereference  

Has anyone know about this rule in findbugs? I searched a lot but I can not find a good sample code (in Java) which describe this rule, unfortunately findbugs site did not have any sample code or good description about this rule.

Why does this violation appear?

Answer

Bharat Sinha picture Bharat Sinha · Sep 3, 2012

It says here

NP: Possible null pointer dereference (NP_NULL_ON_SOME_PATH)

There is a branch of statement that, if executed, guarantees that a null value will be dereferenced, which would generate a NullPointerException when the code is executed. Of course, the problem might be that the branch or statement is infeasible and that the null pointer exception can't ever be executed; deciding that is beyond the ability of FindBugs.

If you would have posted some code it would be easier to answer.

EDIT I don't see a lot of documentation but here is one example! Hope this helps!