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 false positive on enum inside enums #2946

Closed
adangel opened this issue Nov 25, 2020 · 1 comment
Closed
Labels
a:false-positive PMD flags a piece of code that is not problematic
Projects
Milestone

Comments

@adangel
Copy link
Member

adangel commented Nov 25, 2020

Affects PMD Version: 6.29.0

Rule: SwitchStmtsShouldHaveDefault

Description:

If a switch-case over a enum is used inside the enum itself, PMD wrongly requests to add a default case, even though the switch statement is exhaustive. The switch is over this:

Code Sample demonstrating the issue:

package myPackage;

public enum GradeSystem {

    SysA, SysB;

    public boolean isValid() {
      switch (this) { // false-positive
        case SysA:
        case SysB:
          return true;
      }
      
      return false;
    }
}

Result:
myPackage/GradeSystem.java:8: Switch statements should have a default label

Expected outcome:

  • Does PMD report a violation, where there shouldn't be one? -> false-positive

Running PMD through: CLI

@adangel
Copy link
Member Author

adangel commented Apr 22, 2023

This has been fixed with PMD 7.0.0-rc1.

@adangel adangel closed this as completed Apr 22, 2023
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
No open projects
PMD 7
  
Done
Development

No branches or pull requests

2 participants