Skip to content

missing-switch-default

Javasuspiciousno fixdefault: warn

Reports a switch statement that has no default label.

Without default, a value that no case names is ignored without notice, so a new enum constant or an unexpected input falls through the switch and the program goes on with the wrong state.

To fix, add a default that handles the case or throws.

Reported
...
} catch (Exception e) {
// ignored
}
switch (x) {
case 1:
g();
}
...
java:
lint:
rules:
missing-switch-default: warn # off, warn (default), error

Suppress one line with sudsy-disable-next-line missing-switch-default in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
checkstyle MissingSwitchDefault full