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] SwitchStmtsShouldHaveDefault triggered when default case is present #3605

Closed
karel1980 opened this issue Nov 9, 2021 · 0 comments · Fixed by #3805
Closed

[java] SwitchStmtsShouldHaveDefault triggered when default case is present #3605

karel1980 opened this issue Nov 9, 2021 · 0 comments · Fixed by #3805
Assignees
Labels
a:false-positive PMD flags a piece of code that is not problematic
Milestone

Comments

@karel1980
Copy link

karel1980 commented Nov 9, 2021

Affects PMD Version:
6.40.0

Rule:
PMD.SwitchStmtsShouldHaveDefault
https://pmd.github.io/pmd-6.40.0/pmd_rules_java_bestpractices.html#switchstmtsshouldhavedefault

Description:

Code Sample demonstrating the issue:

enum State {
  ON, OFF
}

... switch(state) {
      case ON -> System.out.println("it is on");
      case OFF -> System.out.println("it is off");
      default -> System.out.println("it is neither on nor off - should not happen? maybe null?")
    }

Expected outcome:
No violation

** Actual outcome:**
PMD reports a violation at line switch(state), but that's wrong. That's a false positive.

Running PMD through: Gradle

@karel1980 karel1980 added the a:false-positive PMD flags a piece of code that is not problematic label Nov 9, 2021
@oowekyala oowekyala added this to the 6.43.0 milestone Feb 8, 2022
@oowekyala oowekyala self-assigned this Feb 22, 2022
adangel added a commit to adangel/pmd that referenced this issue Feb 25, 2022
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
Development

Successfully merging a pull request may close this issue.

2 participants