Search code examples
javafindsonarqubefindbugs

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


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?


Solution

  • 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!