SonarSource / sonar-dotnet

Code analyzer for C# and VB.NET projects
https://redirect.sonarsource.com/plugins/csharp.html
GNU Lesser General Public License v3.0
796 stars 228 forks source link

SE: Avoid FPs in concurrent code #9509

Open Tim-Pohlmann opened 4 months ago

Tim-Pohlmann commented 4 months ago

Concurrent code can easily cause FPs in our symbolic execution engine. E.g.:

class ErrorLogger
{
    public Queue<Exception> Queue { get; set; }

    public async Task Start()
    {
        Queue = new();

        do
        {
            await Task.Delay(1000);
            if (Queue.Dequeue() is { } exception)    // FP: S4158
                Console.WriteLine(exception);
        }
        while (true);
    }
}

We should investigate approaches to increase our precision for concurrent code.

Some ideas: