Using c# null conditional operator breaks the rule analysis

Please provide

  • Windows
  • v6.12.0.59751
  • c#
  • connected mode to SonarQube (8.9.6 (build 50800))
static void Main(string[] args)
{
   object o = null;
   var test = o.ToString(); // Noncompliant, always null
   var list = new List<int>();
   //var listCount = list?.Count;

   Console.ReadLine();
}

Reports s2259. If commented line is uncommented (it uses null conditional operator), then the s2259 is no longer reported.

Hey there.

This false-positive should be fixed in SonarQube v9.9 LTS – it looks like an upgrade is in your future!

Great! Will it also fix the local results from SonarLint? As far as I understand it’s a different analyzer. Also it’s not a false positive but more a false negative, the rule does not report error if null conditional operator is used in the file.

Ah, I read a bit too fast.

I tested against SonarQube v9.9 and S2259 was not reported whether or not that line was commented out. I’ll flag this for an expert to look at.

Hello GoranSiska

S2259 does not support ?. yet. We are working on improving S2259 and the issue will be fixed in a future version.

Best Martin

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