Empty Switch Statement
ID |
java.empty_switch_statement |
Severity |
info |
Remediation Complexity |
medium |
Remediation Risk |
low |
Remediation Effort |
medium |
Resource |
Code Smell |
Language |
Java |
Tags |
code-style, unused-code |
Rationale
An empty switch statement evaluates its selector expression but has no cases to match. The construct is dead code that adds unnecessary complexity and typically indicates either an unfinished implementation or a leftover from refactoring:
switch (value) {
// Nothing here
}
Remediation
Either add the intended case labels or remove the empty switch entirely:
// Option 1: add cases
switch (value) {
case 1:
handleOne();
break;
default:
handleOther();
break;
}
// Option 2: remove the empty switch