
resources.report.rules.pmd.MissingBreakInSwitch.html Maven / Gradle / Ivy
MissingBreakInSwitch
MissingBreakInSwitch
A switch statement without an enclosed break statement may be a bug.
This rule is defined by the following XPath expression:
//SwitchStatement
[count(.//BreakStatement)=0]
[count(SwitchLabel) > 0]
[count(BlockStatement/Statement/ReturnStatement)
+ count(BlockStatement/Statement/ThrowStatement)
< count (SwitchLabel)]
Example:
public class Foo {
public void bar(int status) {
switch(status) {
case CANCELLED:
doCancelled();
// break; hm, should this be commented out?
case NEW:
doNew();
case REMOVED:
doRemoved();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy