Hi Sonar-Team,
We have a problem with the condition coverage of our java projects when scanning them. The code is something like
AnyEnum object = anyVariable == null || NULL_STATE.equals(anyVariable) ? null : ANY_VALUE;
// or
NumberObject object = anyNullableNumber == null && anyNullableNumber >= 10 ? 1 : 0;
Beside the horrible abstract examples sonar shows 4 conditions which we have to cover. The problem is, that it is not possible for a variable to be null or any value at the same time. Therefore it is not testable. This is a feature of java not to check the second condition of the || or the && operator when the first is true (for ||) or false (for &&). We use this mechanism e.g. for nullchecking in the same line.
Sonar is not able to get, that in these cases there are just 3 coniditions which we are able to cover and therefore the pipeline fails.
Ofcourse we could decrease our condition coverage or change our code in order to fit to sonar, but as we do not change our code for tests we do not want to change for sonar either.
We would be very pleased to receive feedback
Greetings
Laksuh
- ALM used: GitLab
- CI system used: GitLab CI
- Scanner command used when applicable:
mvn sonar:sonar -Dsonar.host.url=MASKED -Dsonar.organization=MASKED -Dsonar.projectKey=MASKED -Dsonar.qualitygate.wait=true
- Languages of the repository: Java