Pattern: Fall-through in switch
statement
Issue: -
This rule enforces convention to comment any fall-throughs (multiple case statements before termination) in switch
block. Any of the following comments that communicate the idea of fall-through is sufficient: fallthru
, fall through
, fallthrough
, falls through
and fallsthrough
(case sensitive).
<module name="FallThrough"/>
Example of incorrect code:
switch (input) {
case 1:
case 2:
prepareOneOrTwo();
case 3:
handleOneTwoOrThree();
break;
default:
handleLargeNumber(input);
}
Example of correct code:
switch (input) {
case 1:
case 2:
prepareOneOrTwo();
// fall through
case 3:
handleOneTwoOrThree();
break;
default:
handleLargeNumber(input);
}