Useless Control Flow (Identical If/Else Branches)

ID

java.useless_control_flow

Severity

info

Remediation Complexity

auto_fix

Remediation Risk

low

Remediation Effort

low

Resource

Code Smell

Language

Java

Tags

CWE:561, code-style

Description

Reports if/else statements where the then-branch and else-branch have identical bodies. The conditional branching serves no purpose when both paths execute the same code.

Rationale

Identical branches indicate a copy-paste error, unfinished refactoring, or dead condition. The condition evaluation is wasted effort, and readers will be confused about the intent.

// Bad - branches are identical
if (isAdmin) {
    sendEmail(user);
} else {
    sendEmail(user);
}

Remediation

Remove the condition and keep a single copy of the code, or fix the branch that should differ.

// Good - no useless branching
sendEmail(user);

// Or: fix the intended difference
if (isAdmin) {
    sendAdminEmail(user);
} else {
    sendUserEmail(user);
}

References