False positive null pointer C#

Make sure to read this post before raising a thread here:

SonarScanner for MSBuild 5.11

if ((response?.Data?.Results?.Count ?? 0) == 0) return;

offset += response.Data.Results.Count;

Flagged as “‘response’ is null on at least one execution path.”.

If ‘response’ variable was equal to null it would return at first statement, therefor execution cannot reach 2nd line.

Hey there.

What version of SonarQube are you using (or are you using SonarCloud)?

Hi Colin,

We are using a SonarQube server, version 8.9.9.

SonarScanner for MSBuild 5.11, SonarScanner

Hello jmcgee,

Thank you for reporting this false positive.
We are planning to improve the support for null coalescing operators for the rule in the future and I can confirm that this is a known false positive.

Best Martin

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