Our website uses cookies to enhance your browsing experience.
Accept
to the top
>
>
>
Examples of errors detected by the...

Examples of errors detected by the V6004 diagnostic

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


Elasticsearch

V6004 The 'then' statement is equivalent to the 'else' statement. ClusterShardLimitIT.java 52


public void testMinimumPerNode() {
    int negativeShardsPerNode = between(-50_000, 0);
    try {
        if (frequently()) {
            clusterAdmin().prepareUpdateSettings(....)
                .setPersistentSettings(
                    Settings.builder()
                    .put(shardsPerNodeKey, negativeShardsPerNode)
                    .build()
                )
                .get();
        } else {
            clusterAdmin().prepareUpdateSettings(....)
                .setPersistentSettings(
                    Settings.builder()
                    .put(shardsPerNodeKey, negativeShardsPerNode)
                    .build()
                )
                .get();
        }
        fail("should not be able to set negative shards per node");
    } catch (IllegalArgumentException ex) {
        ....
    }
}

Elasticsearch

V6004 The 'then' statement is equivalent to the 'else' statement. BulkByScrollTaskStatusTests.java 189


protected BulkByScrollTask.Status doParseInstance(
                        XContentParser parser
                        ) throws IOException {
    XContentParser.Token token;
    if (parser.currentToken() == XContentParser.Token.START_OBJECT) {
        token = parser.nextToken(); // <=
    } else {
        token = parser.nextToken(); // <=
    }
    ensureExpectedToken(XContentParser.Token.START_OBJECT, token, parser);
    token = parser.nextToken();
    ensureExpectedToken(XContentParser.Token.FIELD_NAME, token, parser);
    return innerParseStatus(parser);
}

CustomNPC+

V6004 The 'then' statement is equivalent to the 'else' statement. GuiMailbox.java 76


private String getTimePast() {
  ....
  if(selected.timePast > 3600000){
    int hours = (int) (selected.timePast / 3600000);
    if(hours == 1)
      return hours + " " +
        StatCollector.translateToLocal("mailbox.hour");
    else
      return hours + " " +
        StatCollector.translateToLocal("mailbox.hours");
  }
  int minutes = (int) (selected.timePast / 60000);
  if(minutes == 1)
    return minutes + " " +
      StatCollector.translateToLocal("mailbox.minutes");
  else
    return minutes + " " +
      StatCollector.translateToLocal("mailbox.minutes");
}

GeoServer

V6004 The 'then' statement is equivalent to the 'else' statement. GeoServerApplication.java 116, GeoServerApplication.java 118


public static String getMessage(Component c, Exception e) {
  if (e instanceof ValidationException) {
    ValidationException ve = (ValidationException) e;
    try {
      if (ve.getParameters() == null) {
        return new ParamResourceModel(ve.getKey(), c,
                                      ve.getParameters()).getString();
      } else {
        return new ParamResourceModel(ve.getKey(), c,
                                      ve.getParameters()).getString();
      }
    } catch (Exception ex) {
      LOGGER.log(Level.FINE, "i18n not found, proceeding with default message",
                 ex);
    }
  }
  // just use the message or the toString instead
  return e.getMessage() == null ? e.toString() : e.getMessage();
}

GeoServer

V6004 The 'then' statement is equivalent to the 'else' statement. WicketHierarchyPrinter.java 40, WicketHierarchyPrinter.java 42


/** Utility method to dump a single component/page to standard output */
public static void print(Component c, boolean dumpClass,
                         boolean dumpValue, boolean dumpPath
) {
  WicketHierarchyPrinter printer = new WicketHierarchyPrinter();
  printer.setPathDumpEnabled(dumpClass);
  printer.setClassDumpEnabled(dumpClass);
  printer.setValueDumpEnabled(dumpValue);
  if (c instanceof Page) {
    printer.print(c);                                         // <=
  } else {
    printer.print(c);                                         // <=
  }
}

IntelliJ IDEA Community Edition

V6004 The 'then' statement is equivalent to the 'else' statement. YAMLScalarTextImpl.java(116), YAMLScalarTextImpl.java(119)


protected List<....> getEncodeReplacements(CharSequence input) {
  for (int i = 0; i < input.length(); ++i) {
    if (input.charAt(i) == '\n') {
      final String replacement;
      if (i + 1 >= input.length() ||
        YAMLGrammarCharUtil.isSpaceLike(input.charAt(i + 1)) ||
        input.charAt(i + 1) == '\n' ||
        currentLineIsIndented)
      {
        replacement = "\n" + indentString;
      }
      else
      {
        replacement = "\n" + indentString;
      }
      ....
      continue;
    }
    ....
  }
}

NGB

V6004 The 'then' statement is equivalent to the 'else' statement. FeatureIndexDao.java(852), FeatureIndexDao.java(854)


private String getGroupByField(final List<VcfFile> files, final String groupBy){
    final VcfIndexSortField sortField = VcfIndexSortField.getByName(groupBy);
    if (sortField == null) {
        ....
        if (   infoItem.getType() == VCFHeaderLineType.Integer
            || infoItem.getType() == VCFHeaderLineType.Float) {
            return infoItem.getName().toLowerCase();
        } else {
            return infoItem.getName().toLowerCase();
        }
    } else {
        if (   sortField.getType() == SortField.Type.INT
            || sortField.getType() == SortField.Type.FLOAT) {
            return sortField.getField().fieldName;
        } else {
            return sortField.getField().fieldName;
        }
    }
}

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);
    }
}

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;
    }
  }
}

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)

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));
 }
 ....
}