always false conditional statement - sonarqube

testing

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

Peska

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.

edited at
0

Comments

0 comments
Login to comment

Related

Null-conditional operator always true in if statement when should be false

Conditional statement always returns false (inline-style)

Java if () statement always false?

if statement always returning false

Append always returning false statement

python if statement always returns False

If statement in C always returning false

Why is my if statement always false?

Excel If Statement always shows false

TypeScript tuples conditional comparison always evaluates to false

regex101 Conditional statement is always else

MIPS Conditional Statement BNE is always branching

Flutter conditional statement always renders the true

Jenkins Pipeline - if statement always returns false

Why is the first condition of "else if" statement always false?

If /else statement in Twilio Function always return false

Javascript: False if statement always evaluates as true

SonarQube claims condition to always evaluate to false for fields accessed with "this."

Why is my if statement always evaluating to false within a switch statement?

The boolean return statement inside a for loop and if statement is always returning false in java

Conditional that tests for a dictionary key's presence is always False

Why does if conditional statement terminate after else if(which is false)although there is another else if in this if conditional statement?

jQuery: Stop window height recalclulation once conditional statement returns false

Function returning always false when using a Boolean on my statement

{% block something %} always being displayed despite being False in an if-statement

The !preg_match() function in a condition statement is false always

If statement always returning false while trying to detect the color of a pixel

Bash IF statement: string comparison of command output always false

checking array value with if statement always returns (output) false (else)