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

Fix S2259 FP: SE engine doesn't take into account collection extension method `Any`

Open sebastien-marichal opened this issue 1 year ago • 1 comments

From this community post.

This might be fixed as part of #7457:

Learn from well-known (extension-) methods like list.Any()

void Method(Exception[] array)
{
    if (array.Any())
    {
        Exception exception = array.FirstOrDefault();
        Console.WriteLine(exception.Message); // Noncompliant - FP if Any is true, FirstOrDefault will never return null
    }
}

sebastien-marichal avatar Oct 27 '23 08:10 sebastien-marichal