Sonar scanner server shows more conditions to cover then expected

Hello,
I used the sonar scanner plugin on jenkins, and i scanned my code with maven, and created a jacoco report, which then I pushed to sonarqube server.

And once i go there to see the analysis, I see the follwing:

My code:
if (((Map) ((Map) methodSettings.coverityBuild))?.compiler) {…}

it is obvious, an IF statement, it can have only 2 states, either true or false, but in sonarqube, i see the following statement:

image

Why is that? And how can i make a junit test to cover the 2 phantom conditions?

thank you for your time!

Hi,

SonarQube doesn’t calculate this value, it only imports from the jacoco report. You’ll have to check why jacoco is considering 4 conditions.

I’m not sure what language this is, but ?. is usually a null check. So it’s not just a simple “.compiler can have only 2 states”. I can see 3 possible states:

  • methodSettings.coverityBuild is null
  • coverityBuild is not null and .compiler is true
  • coverityBuild is not null and .compiler is false

edit: oh, it looks Groovy code. IIRC, the “fourth condition” is:

  • coverityBuild is not null and .compiler doesn’t exist (Groovy returns a null value in this access)

yes, it is groovy
Ok, i think I understand.
Also, thanks for the jacoco info :slight_smile: