Examples of errors detected by the V6004 diagnostic

V6004. The 'then' statement is equivalent to the 'else' statement.


SonarQube

V6004 [CWE-691] The 'then' statement is equivalent to the 'else' statement. Check lines: 76, 78. OneIssuePerLineSensor.java 76


public static final String EFFORT_TO_FIX_PROPERTY =
  "sonar.oneIssuePerLine.effortToFix";
public static final String FORCE_SEVERITY_PROPERTY =
  "sonar.oneIssuePerLine.forceSeverity";

private void createIssues(InputFile file, SensorContext context, String repo) {
 ....
 if (context.getSonarQubeVersion().isGreaterThanOrEqual(Version.create(5, 5))) {
   newIssue.gap(context.settings().getDouble(EFFORT_TO_FIX_PROPERTY));
 } else {
   newIssue.gap(context.settings().getDouble(EFFORT_TO_FIX_PROPERTY));
 }
 ....
}

XMage

V6004 The 'then' statement is equivalent to the 'else' statement. AsThoughEffectImpl.java(35), AsThoughEffectImpl.java(37)


@Override
public boolean applies(....) {
  // affectedControllerId = player to check
  if (getAsThoughEffectType().equals(AsThoughEffectType.LOOK_AT_FACE_DOWN)) {
    return applies(objectId, source, playerId, game);
  } else {
    return applies(objectId, source, playerId, game);
  }
}

Similar errors can be found in some other places:

  • V6004 The 'then' statement is equivalent to the 'else' statement. GuiDisplayUtil.java(194), GuiDisplayUtil.java(198)

WildFly

V6004 The 'then' statement is equivalent to the 'else' statement. WeldPortableExtensionProcessor.java(61), WeldPortableExtensionProcessor.java(65)


@Override
public void deploy(....) throws DeploymentUnitProcessingException {
  if (PrivateSubDeploymentMarker.isPrivate(deploymentUnit)) {
    if (!WeldDeploymentMarker.isPartOfWeldDeployment(deploymentUnit)) {
      return;
    }
  }
  else {
    if (!WeldDeploymentMarker.isPartOfWeldDeployment(deploymentUnit)) {
      return;
    }
  }
}

Bouncy Castle

V6004 The 'then' statement is equivalent to the 'else' statement. BcAsymmetricKeyUnwrapper.java(36), BcAsymmetricKeyUnwrapper.java(40)


public GenericKey generateUnwrappedKey(....) throws OperatorException {
    ....
    byte[] key = keyCipher.processBlock(encryptedKey, 0, encryptedKey.length);
    if (encryptedKeyAlgorithm.getAlgorithm()
                             .equals(PKCSObjectIdentifiers.des_EDE3_CBC)) {
        return new GenericKey(encryptedKeyAlgorithm, key);
    } else {
        return new GenericKey(encryptedKeyAlgorithm, key);
    }
}


Bugs Found

Checked Projects
414
Collected Errors
14 218
This website uses cookies and other technology to provide you a more personalized experience. By continuing the view of our web-pages you accept the terms of using these files. If you don't want your personal data to be processed, please, leave this site. Learn More →
Accept