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

前端 未结 5 650
悲哀的现实
悲哀的现实 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:35

    a sample code is something like this.

    String s = null ;
    if (today is monday){
        s = "Monday" ;
    else if (today is tuesday){
        s = "Tuesday" ;
    }
    System.out.println(s.length()); //Will throw a null pointer if today is not monday or tuesday.
    

提交回复
热议问题