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

[java] ImplicitSwitchFallThrough: False-positive with nested switch statements #4948

Closed
sratz opened this issue Apr 10, 2024 · 0 comments · Fixed by #4963
Closed

[java] ImplicitSwitchFallThrough: False-positive with nested switch statements #4948

sratz opened this issue Apr 10, 2024 · 0 comments · Fixed by #4963
Assignees
Labels
a:false-positive PMD flags a piece of code that is not problematic
Milestone

Comments

@sratz
Copy link
Contributor

sratz commented Apr 10, 2024

Affects PMD Version: 7.0.0

Rule: category/java/errorprone.xml/ImplicitSwitchFallThrough

Description:

Code Sample demonstrating the issue:

public class Test {

	boolean foo(String a, String b) {

		switch (a) {
		case "a1":
			return true;
		case "a2":
			switch (b) {
			case "b1":
				return true;
			default:
				return false;
			}
		default:   // <--- false-positive ImplicitSwitchFallThrough
			return false;
		}
	}

}

Outcome:

PMD reports a violation at line 15, but that's wrong. That's a false positive.

the outer case "a2" cannot fall through, since the inner switch is exhaustive and returns from all branches.

Running PMD through: CLI | Maven

@sratz sratz added the a:false-positive PMD flags a piece of code that is not problematic label Apr 10, 2024
@oowekyala oowekyala self-assigned this Apr 16, 2024
@adangel adangel added this to the 7.1.0 milestone Apr 25, 2024
adangel added a commit that referenced this issue Apr 25, 2024
…ed switch statement (#4963)

Merge pull request #4963 from oowekyala:issue4948-switch-fallthrough
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:false-positive PMD flags a piece of code that is not problematic
Projects
None yet
3 participants