while analyzing my code in sonarqube i'm getting an error saying the conditional always evaluates to false and subsequent code is never executed in the below code:
private RedirectItem FindItemToItemRedirect(string url)
{
var redirectDefinition = RedirectDefinition?.ItemsRedirects;
if (!redirectDefinition?.Any() ?? false)
return null;
RedirectItem result;
if (redirectDefinition.TryGetValue(url, out result))
return result;
return null;
}
its saying the if (!redirectDefinition?.Any() ?? false)
is always false and the null beneath it is never executed. however in my IDE/with resharper i am getting no errors for this in the code. is this a false positive in sonarqube and i should just suppress it?
thanks
This is a known bug in sonarqube described in here: https://github.com/SonarSource/sonar-dotnet/issues/2369
Instead of suppressing it, you can write:
if (!redirectDefinition?.Any().GetValueOrDefault())
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments