SonarLint don't find multiple bugs

26 views
Skip to first unread message

fanny...@gmail.com

unread,
Dec 2, 2016, 8:12:19 AM12/2/16
to SonarQube

Hi ,

Sorry for my english and the waste of time if you already know the issue (i don't find it on other subject).

I have this code:
      if (doLog) {
            sbEnf = new StringBuilder(" \t Enfouissement \t");
            sbEvent = new StringBuilder(" \t Event \t");
            sbHr = new StringBuilder(" \t Hauteur Reelle \t");
            sbHs = new StringBuilder(" \t Hauteur Solide \t");
        }

....
...
....

    if (doLog) {
            sbEnf.append(enfMax[0][0][0]);
            sbEnf.append("\t");
            sbHr.append(hr[0][0]);
            sbHr.append("\t");
            sbHs.append(hs[0][0]);
            sbHs.append("\t");
        }


SonarLint find the issue :
NullPointerException might be thrown as 'sbEnf' is nullable here  

but not for the other variables sbEvent ,sbHr and sbHs .

Thank you

Nicolas Peru

unread,
Dec 2, 2016, 11:16:22 AM12/2/16
to fanny...@gmail.com, SonarQube
Hi, 

I assume you are doing java. 
It is almost impossible to tell you precisely what is going on here without more context. (what is doLog variable ? a field, a parameter? a local variable?). 
So please provide a detail context and also explain clearly what is the problem. I assume (again) that you would expect to have multiple issue raised whereas the analyzer will raise only one. That is on purpose.

If the issue raised for sbEnf is correct (which seems to be the case from what you are saying) that would mean that this line can throw a NPE and thus the following lines are not evaluated by the analyzer thus not raising an issue even if there might also be a NPE if they were (but what would be the point to tell you that : your program already crashed before those lines). 

HTH,
Cheers

--
You received this message because you are subscribed to the Google Groups "SonarQube" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarqube+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/0f7f60e4-7ef1-4994-a934-8aef8fa3a6f6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
Nicolas PERU | SonarSource
Senior Developer
http://sonarsource.com

fanny...@gmail.com

unread,
Dec 6, 2016, 3:46:27 AM12/6/16
to SonarQube, fanny...@gmail.com

For Everyone see the discussion:


Me :


Thank for your answer.

You assume correctly.
for the context:
- yes ,i am doing java  ( i put a tag)
- doLog is boolean variable.

I don't understand why SonarLint don't raise multiple issues (and why it is the pupose), because the first variable (sbEnf) can be good but not the second  (sbHr) or the third and vice versa.
Sonar:

Hi,
For this issue the analyzer is exploring by path of execution and I guess (again) that in your case there are no path where the first variable is not null and the second is.
Cheers


Me:
you are right ,thank you


Reply all
Reply to author
Forward
0 new messages