Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FallThrough check false positive with labelled break #11230

Closed
sbj42 opened this issue Jan 24, 2022 · 6 comments · Fixed by #14199
Closed

FallThrough check false positive with labelled break #11230

sbj42 opened this issue Jan 24, 2022 · 6 comments · Fixed by #14199

Comments

@sbj42
Copy link

sbj42 commented Jan 24, 2022

I have read check documentation: https://checkstyle.sourceforge.io/config_coding.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

> javac Test.java
(success)

> type 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">
    </module>
  </module>
</module>

> type Test.java
public class Test {
    public int test(int a, int b) {
        top: switch (a) {
            case 1:
                switch (b) {
                    case 10:
                        break top;
                    default:
                        return 11;
                }
            case 2: // line 11
                return 2;
        }
        return -1;
    }
}

> java -jar checkstyle-0.2.1-all.jar -c config.xml Test.java
Starting audit...
[ERROR] Test.java:11:13: Fall through from previous branch of the switch statement. [FallThrough]
Audit done.
Checkstyle ends with 1 errors.

Expected result is no errors. This code never falls through from case 1 to case 2. The problem seems to only happen with a labelled break. If I use return 11 instead of break top then checkstyle does not find a problem.

@sbj42
Copy link
Author

sbj42 commented Jan 24, 2022

#3885 is also about a FallThrough false positive, but it focuses on infinite loops, which are harder to detect.

@romani
Copy link
Member

romani commented Mar 1, 2022

We should not violate break to label. Any break should be good to consider it as valid code.

@romani
Copy link
Member

romani commented Mar 18, 2023

rivanov@p5510:/var/tmp$ 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">
    <property name="charset" value="UTF-8"/>

    <module name="TreeWalker">
       <module name="FallThrough"/>
    </module>

</module>

rivanov@p5510:/var/tmp$ cat Test.java 
public class Test {
    public int test(int a, int b) {
        top: switch (a) {
            case 1:
                break top;
            case 2: // line 11
                return 2;
        }
        return -1;
    }
}
rivanov@p5510:/var/tmp$ java -jar checkstyle-10.9.1-all.jar -c config.xml Test.java
Starting audit...
Audit done.

we need to behave same as in this case, nested switch shoudl not be something special

@rnveach
Copy link
Member

rnveach commented Mar 18, 2023

@romani NonEmptyAtclauseDescription is a javadoc check. What does this have to do with FallThroughCheck which is for switches?

@romani
Copy link
Member

romani commented Mar 18, 2023

fixed, same behavior.

@aayushRedHat
Copy link
Contributor

@romani I am taking this

relentless-pursuit pushed a commit to relentless-pursuit/checkstyle that referenced this issue Dec 29, 2023
relentless-pursuit pushed a commit to relentless-pursuit/checkstyle that referenced this issue Feb 1, 2024
relentless-pursuit pushed a commit to relentless-pursuit/checkstyle that referenced this issue Feb 1, 2024
relentless-pursuit pushed a commit to relentless-pursuit/checkstyle that referenced this issue Feb 2, 2024
relentless-pursuit pushed a commit to relentless-pursuit/checkstyle that referenced this issue Feb 2, 2024
relentless-pursuit pushed a commit to relentless-pursuit/checkstyle that referenced this issue Feb 25, 2024
relentless-pursuit pushed a commit to relentless-pursuit/checkstyle that referenced this issue Feb 25, 2024
relentless-pursuit pushed a commit to relentless-pursuit/checkstyle that referenced this issue Feb 25, 2024
relentless-pursuit pushed a commit to relentless-pursuit/checkstyle that referenced this issue Feb 27, 2024
relentless-pursuit pushed a commit to relentless-pursuit/checkstyle that referenced this issue Mar 10, 2024
relentless-pursuit pushed a commit to relentless-pursuit/checkstyle that referenced this issue Mar 10, 2024
relentless-pursuit pushed a commit to relentless-pursuit/checkstyle that referenced this issue Mar 10, 2024
relentless-pursuit pushed a commit to relentless-pursuit/checkstyle that referenced this issue Mar 10, 2024
relentless-pursuit pushed a commit to relentless-pursuit/checkstyle that referenced this issue Mar 10, 2024
relentless-pursuit pushed a commit to relentless-pursuit/checkstyle that referenced this issue Mar 15, 2024
relentless-pursuit pushed a commit to relentless-pursuit/checkstyle that referenced this issue Mar 15, 2024
relentless-pursuit pushed a commit to relentless-pursuit/checkstyle that referenced this issue Mar 15, 2024
relentless-pursuit pushed a commit to relentless-pursuit/checkstyle that referenced this issue Mar 15, 2024
relentless-pursuit pushed a commit to relentless-pursuit/checkstyle that referenced this issue Mar 15, 2024
relentless-pursuit pushed a commit to relentless-pursuit/checkstyle that referenced this issue Mar 15, 2024
relentless-pursuit pushed a commit to relentless-pursuit/checkstyle that referenced this issue Mar 15, 2024
relentless-pursuit pushed a commit to relentless-pursuit/checkstyle that referenced this issue Mar 15, 2024
relentless-pursuit pushed a commit to relentless-pursuit/checkstyle that referenced this issue Mar 15, 2024
relentless-pursuit pushed a commit to relentless-pursuit/checkstyle that referenced this issue Mar 15, 2024
relentless-pursuit pushed a commit to relentless-pursuit/checkstyle that referenced this issue Mar 16, 2024
relentless-pursuit pushed a commit to relentless-pursuit/checkstyle that referenced this issue Mar 16, 2024
relentless-pursuit pushed a commit to relentless-pursuit/checkstyle that referenced this issue Mar 16, 2024
@romani romani added the bug label Mar 23, 2024
@github-actions github-actions bot added this to the 10.15.0 milestone Mar 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants