Zum Inhalt springen

Duplicate Condition Branches (ARCH4190)

Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.

Key java.quality.duplicate-branches · Severity warning · Category quality

if/else or case branches with identical bodies are redundant and often hide a logic mistake. Merge the branches.

String label(Status s) {
if (s == Status.ACTIVE) return "ok";
else if (s == Status.PENDING) return "ok";
else return "no";
}
String label(Status s) {
return (s == Status.ACTIVE || s == Status.PENDING) ? "ok" : "no";
}

Merge the conditions of branches that share a body, or fix the logic if the duplication was a mistake.