S2589 false alarm in SonarLint, VS 2022

I get a false positive for the below code in SonarLint v7.5.0.82292, Visual Studio 2022, for C# language:
S2589 / condition always evaluates to False

int counter = 0;
while (true)
{
	Thread.Sleep(10);
	if (counter++ > 5)
		break;
}

Hey there.

I believe we’re working on a fix for this right now (Rework loop handling to also work for counter variables that are not part of the loop condition · Issue #8474 · SonarSource/sonar-dotnet · GitHub)

1 Like