Duplicate Branches
ID |
java.duplicate_branches |
Severity |
info |
Remediation Complexity |
medium |
Remediation Risk |
low |
Remediation Effort |
medium |
Resource |
Code Smell |
Language |
Java |
Tags |
code-style |
Description
Reports if/else statements where the then-block and else-block have identical source code. Identical branches mean the condition has no effect, which is almost always a copy-paste mistake.
Rationale
When both branches of a conditional execute the same code, the conditional is dead logic. This typically happens during copy-paste coding or incomplete refactoring.
// Bad -- condition has no effect
if (isAdmin) {
return 42;
} else {
return 42;
}
Remediation
Remove the conditional or fix the copy-paste error by implementing distinct logic in each branch.
return 42; // No need for the conditional