sonar-dotnet
sonar-dotnet copied to clipboard
S2259 FP: Null conditional combined with null coalescing
Description
S2259 is incorrectly reported when using null conditional with null coalescing operator.
Repro steps
private void Sample()
{
string someString = null;
if (!someString?.Contains("a") ?? true)
Console.WriteLine("It's null or doesn't contain 'a'");
else
Console.WriteLine(someString.Length); //S2259 reported here
}
Expected behavior
S2259 should not be reported in this case.
Actual behavior
S2259 is reported.
Hi @przemyslaw-piescik ,
Thank you for reporting this case, I can confirm it as False Positive. We already have similar issue reported in #2528 with the same root cause that you can follow. I'll close this one.
I'll actually keep this one opened, as it's isolated from the integer constraint issue reported in the other one.