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] TooFewBranchesForASwitchStatement should consider Switch Expressions #5250

Closed
adangel opened this issue Oct 4, 2024 · 0 comments · Fixed by #5251
Closed

[java] TooFewBranchesForASwitchStatement should consider Switch Expressions #5250

adangel opened this issue Oct 4, 2024 · 0 comments · Fixed by #5251
Labels
a:false-negative PMD doesn't flag a problematic piece of code
Milestone

Comments

@adangel
Copy link
Member

adangel commented Oct 4, 2024

Affects PMD Version: 7.6.0

Rule: TooFewBranchesForASwitchStatement

Description:
The rule currently only checks Switch Statements, but should also check Switch Expressions.

Therefore, the rule should be renamed to TooFewBranchesForSwitch (remove the statement part)

Code Sample demonstrating the issue:

public class DumbSwitch {
    public String foo(int i) {
        return switch (i) {  // violation expected here
            case 0:
            {
                yield "I am a fish.";
            }
        };
    }
}

Expected outcome:

PMD should report a violation at line ..., but doesn't. This is a false-negative.

Running PMD through: [CLI | Ant | Maven | Gradle | Designer | Other]

@adangel adangel added the a:false-negative PMD doesn't flag a problematic piece of code label Oct 4, 2024
@adangel adangel added this to the 7.7.0 milestone Oct 4, 2024
adangel added a commit to adangel/pmd that referenced this issue Oct 24, 2024
…ern matching and support switch expressions (pmd#5251)

Merge pull request pmd#5251 from adangel:issue-5249-5250
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:false-negative PMD doesn't flag a problematic piece of code
Projects
None yet
1 participant