Then tell us:
- What language is this for?
C#
- Which rule?
S2583 Change this condition so that it does not always evaluate to ‘false’; some subsequent code is never executed.
- Why do you believe it’s a false-positive/false-negative?
False positive
-
Are you using
- SonarQube - which version? - Enterprise Edition Version 9.9.4 (build 87374)
-
How can we reproduce the problem? Give us a self-contained snippet of code (formatted text, no screenshots)
Sadly I can’t give the actual code due to IP restrictions. But it goes something like this:
static void DoSomething(string s)
{
var inWhiteSpace = true;
var followingWhiteSpace = false; // The variable starts off false
foreach (var c in s)
{
if (char.IsWhiteSpace(c))
{
if (inWhiteSpace) // This will be false after the first non white space.
{
continue;
}
followingWhiteSpace = true; // The variable is set to true
inWhiteSpace = true;
continue;
}
inWhiteSpace = false;
if (followingWhiteSpace) // S2583 reported here
{
// Do something
followingWhiteSpace = false;
}
// Do something else
}
}