Null check fallback value is reported as bug but it's not

We use sonar cloud to perform check in the VSTS pipeline. Some of the bugs reported seem to be apparently wrong.

if (entityBaselineBlocks?.Any() ?? false)

it’s a combination of two c# features:

  • null propagation
  • null coalescing operator

Using that combination we’re doing two checks in one if statement. However, sonar report says that the code underneath that condition will be never executed. Could you please check and make appropriate changes?

1 Like

Hi @iamkarlson,

Thank you for your feedback! We are aware that we have a couple of limitations on our rules when using some new syntax like ?, ??, tuple

We sadly cannot commit on a date where we will be able to fix this limitation.

Cheers,
Amaury


EDIT:
You can track this ticket https://github.com/SonarSource/sonar-dotnet/issues/1347

Hi, I haven’t found any solution on github. So let’s keep this ticket open until the issue is resolved. How is it?

@iamkarlson Fine by me (I was just pointing you to the ticket we will use when working on the fix).

I would hope this gets fixed someday, null coalescing checks are far too handy to not use and the number of false positives makes me want to just put the warning to be ignored.

hi @mkahvi - a lot of these false positives got fixes in the 7.16 release ( see release notes )

As you see, https://github.com/SonarSource/sonar-dotnet/issues/1347 is fixed!

If you find a problem exists in 7.16, please open a new topic on this community forum

And welcome to our community forum! :slight_smile:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.