
org.sonar.l10n.flex.rules.flex.SwitchWithoutDefault.html Maven / Gradle / Ivy
The newest version!
Why is this an issue?
The requirement for a final default
clause is defensive programming. The clause should either take appropriate action, or contain a
suitable comment as to why no action is taken.
Noncompliant code example
switch (param) { // Noncompliant - default clause is missing
case 0:
doSomething();
break;
case 1:
doSomethingElse();
break;
}
switch (param) {
default: // Noncompliant - default clause should be the last one
doSomething();
break;
case 0:
doSomethingElse();
break;
}
Compliant solution
switch (param) {
case 0:
doSomethingElse();
break;
default:
doSomethingElse();
break;
}
Resources
© 2015 - 2025 Weber Informatics LLC | Privacy Policy