We have the following code in our system. It is not very pretty, but the rule is a false positive. This condition is not always true. It is possible for the “counter” to be 10.
We are using c#
int counter = 0;
tmin = rnd.NextDouble();
tmax = rnd.NextDouble();
if(tmin < 10 && tmax < 10)
else if(counter < 10)
throw new InvalidOperationException("Could find data transition.");
We ask that users don’t share screenshots of code, can you please share a self-contained snippet of code? And other details, like what language you’re analyzing.
You can find what information makes a great false-positive report here:
I have added the code as a snippet.
Can you also report what product(s) you’re using, and what version?
It is SonarQube 10.2.1.78527 - Developer edition
This looks similar to a known issue that has been reported here – which you can follow along on.
As noted in the ticket:
Apologies for the inconvenience. For the time being, waiting for the issue to be fixed:
- If you are using SonarQube: you can mark the issue as a false-positive in the UI. The rule can also be disabled in your Quality Profile if it’s particularly noisy.
- You can use
#pragma warning disable and
#pragma warning restore to locally disable the rule in the source