sonar-dotnet icon indicating copy to clipboard operation
sonar-dotnet copied to clipboard

Fix S2589 FP with nullable value types

Open csaba-sagi-sonarsource opened this issue 3 years ago • 1 comments

Description

S2589 raises a false positive when used with nullable value types.

Repro steps

protected void Test(decimal? value1, decimal? value2)
{
    if (value1 == null || value2 == null || value1 != value2)
    {
        Console.WriteLine("test");
    }
}

Expected behavior

No issue is raised.

Actual behavior

An issue is riased.

Related information

  • C#/VB.NET Plugins version: 8.33.0.40503

csaba-sagi-sonarsource avatar Dec 28 '21 14:12 csaba-sagi-sonarsource

S2589 will trigger on null, too, e. g.

int? foo = (int?)6 ?? null;

shuebner avatar Jun 01 '22 09:06 shuebner

Fixed by https://github.com/SonarSource/sonar-dotnet/pull/7750