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

前端 未结 5 648
悲哀的现实
悲哀的现实 2021-02-07 11:00

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 a

5条回答
  •  既然无缘
    2021-02-07 11:26

    In simple language, if a variable value is assigned as null, and you try to access it with any inbuilt method like add/get. Then null pointer dereference issue comes with SONAR. Because there are changes for it go null, and throw null pointer exception. Try to avoid it if possible.

    For example:

    File file=null;
    file.getName();
    

    will throw "Possible null pointer dereference"

    It may not happen directly as mentioned in the example, it can be unintentionally.

提交回复
热议问题