S2589 C# False Positive

If your question is about SonarLint in the IntelliJ Platform, VS Code, Visual Studio, or Eclipse, please post it in that sub-category.

Otherwise, please provide:

  • Operating system: Windows 10 Pro
  • IDE name and flavor/env: Visual Studio 2022

And a thorough description of the problem / question:

C# static code analysis: Boolean expressions should not be gratuitous appears to result in a false positive give the following code example.

var initTries = 0;

while (true)
       //some init logic
    catch (Exception ex)

        //log exception

        if (initTries == 3)


Hello @groogiam

Thank you for reporting this. I couldn’t reproduce the issue with the latest version of our analyzer. Note that we made many changes to S2589 in the latest releases. Versions 9.8 and 9.9, from late August to early September, reworked the rule significantly. Therefore, it is essential to know which version of the analyzer was used during the analysis. Can you tell which version of the analyzer you are using?

Best, Martin

I’m using the SonarLint plugin for Visual Studio. Version I’m not sure how to tell which version of the analyzer this plugin uses though. Thanks.

This version of SonarLint embeds version 9.8 of the scanner. The current version is 9.12. The rule was changed a couple of times during that period. I would propose to wait for the next release of the SonarLint plugin and see if the issues persist. If so, please ping me here.

Will do. Thanks.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.