C# NRE not detected for some reason

  • Operating system: Windows 10
  • Visual Studio version: Microsoft Visual Studio Community 2022 (64-bit) - Current Version 17.13.6
  • SonarQube for Visual Studio plugin version: SonarQube for Visual Studio 2022, v8.17.0.12886
  • Programming language you’re coding in: C#
  • Is connected mode used: no

And a thorough description of the problem / question:

A NRE is not detected in the following code:

public class Test
{
	public string Prop { get; set; }
}

public static string GetProp(Test t1, Test t2)
{
	if (t1 != null)
		return t1.Prop;

	if (t2 != null)
		return t1.Prop;

	return string.Empty;
}

static void Main()
{
	var prop = GetProp(null, new Test { Prop = "hey" });
	Console.WriteLine(prop);
}

Obviously, this is a simplified version of what we encountered, but on a colleague’s PC, with VS 2019, it was detected initially, but then after building again, not any more. Super strange.

Hi,

The current version of SonarQube for Visual Studio (formerly SonarLint) is 10.23. Can you upgrade and see if this is still replicable?

 
Thx,
Ann

Hi Ann,
just checked, I have no updates, but meantime SonarQube probably auto-updated to 8.18.0.13071… I can’t find a 10.xx version, even after uninstalled 8.18, so I reinstalled it.
I can confirm, the issue still reproduces with latest SonarQube I could find.
Cheers,
Marton

Edit: confirmed 8.18 is latest available

Hi Marton,

Thanks for checking for updates. I got confused about which IDE you were using, and so I was wrong about the latest version. Sorry about that.

Could you provide your log for this?

 
Thx,
Ann