Switch Default Missing Break

ID

java.switch_default_missing_break

Severity

info

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Reliability

Language

Java

Tags

best-practice, reliability

Description

Reports switch statements where the default case does not end with a break, return, or throw statement. Without a terminating statement, execution falls through to the next case (or out of the switch), which is almost always unintentional for the default branch.

Rationale

A default case without an explicit terminating statement silently falls through, causing unexpected behavior that is hard to debug:

switch (status) {
    case 1:
        handle();
        break;
    default:
        log("unknown");
        // Oops - falls through or exits without clear intent
}

Remediation

Add a break, return, or throw statement to the default case:

switch (status) {
    case 1:
        handle();
        break;
    default:
        log("unknown");
        break;
}