Connected to SonarCloud or SonarQube (and which version): SonarQube 10.2.1
In some cases , the rule “S2583 Conditionally executed code should be reachable” gives false positives in the case the if statement is on a variable that could have been changed in a closure.
In this code, the variable captured get changed, but the rule doe not recognize that, and gives the warning: Change this condition so that it does not always evaluate to 'False'. Some code paths are unreachable. It thinks the if statement will evaluate to false, but in reality, it will evaluate to true.
Thanks a lot for reporting this, it’s indeed an FP.
Our symbolic execution engine does not explore lambdas so it does not detect that captured can be also not 0.
Here is a GitHub issue for you to follow regarding this.
It’s in our future objectives to plan supporting lambdas for the symbolic execution.
Yes, thanks, that is the issue. In the actual code it runs for 1000 times, so making more iterations exploring the loop is not likely going to be the solution.