I have read check documentation: https://checkstyle.org/checks/coding/fallthrough.html#FallThrough
I have downloaded the latest checkstyle from: https://checkstyle.org/cmdline.html#Download_and_Run
I have executed the cli and showed it below, as cli describes the problem better than 1,000 words
Config
kevin@inspiron-15-5510:~/Desktop/check_style$ cat config.xml
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
<module name="TreeWalker">
<module name="FallThrough">
<property name="checkLastCaseGroup" value="true"/>
</module>
</module>
</module>
Code
kevin@inspiron-15-5510:~/Desktop/check_style$ cat Test.java
1 public class Test {
2 void method(int i) {
3 switch(i) {
4 case 0:
5 int j = 22; // fallthru
6 case 1: /* line no :- 6 */
7 int k = 2;
8 break;
9 case 2:
10 i++;
11 // fall thru
12 case 3:
13 i++;
14 break;
15 }
16 }
17
18 void foo(int i){
19 switch(i) {
20 case 1:
21 int fallthru = 2; // fallthru
22 case 2:
23 int fallthrough = 2; // fall thru
24 case 3:
25 break;
26 case 4:
27 int fallthru2 = 3;
28 // fall - thru
29 case 5:
30 int fallthru3 = 4; // This is a fallthru comment
31 case 6:
32 int fallthru4 = 5; // falldown
33 default:
34 }
35 }
36 }
Output
kevin@inspiron-15-5510:~/Desktop/check_style$ java \
-jar /home/kevin/Downloads/checkstyle-10.12.2-all.jar -c config.xml Test.java
Starting audit...
[ERROR] Test.java:22:7: Fall through from previous branch of the switch statement. [FallThrough]
[ERROR] Test.java:24:7: Fall through from previous branch of the switch statement. [FallThrough]
[ERROR] Test.java:29:7: Fall through from previous branch of the switch statement. [FallThrough]
[ERROR] Test.java:31:7: Fall through from previous branch of the switch statement. [FallThrough]
[ERROR] Test.java:33:9: Fall through from previous branch of the switch statement. [FallThrough]
Audit done.
Checkstyle ends with 5 errors.
Expectation
If we are showing violation on line 22 and line 24 Then line no 6 also should show violation
I have read check documentation: https://checkstyle.org/checks/coding/fallthrough.html#FallThrough
I have downloaded the latest checkstyle from: https://checkstyle.org/cmdline.html#Download_and_Run
I have executed the cli and showed it below, as cli describes the problem better than 1,000 words
Config
Code
Output
Expectation
If we are showing violation on line 22 and line 24 Then line no 6 also should show violation