Skip to content

[java] TooFewBranchesForSwitch false-positive with switch using list of case constants #5287

Closed
@boris-petrov

Description

Affects PMD Version:
7.7.0

Rule:
TooFewBranchesForSwitch.

Description:
Having multiple labels in a single case should be considered the same as multiple cases. So no TooFewBranchesForSwitch should be triggered for the code below:

Code Sample demonstrating the issue:

return switch (someEnumValue) {
    case A, B, C -> 1;
    default -> 0;
};

Expected outcome:
No violation.

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

Metadata

Assignees

No one assigned

    Labels

    a:false-positivePMD flags a piece of code that is not problematic

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions