Skip to content

[java] NonCaseLabelInSwitch should consider switch expressions #5257

@adangel

Description

@adangel

Affects PMD Version: 7.6.0

Rule: NonCaseLabelInSwitchStatement

Description:

It currently only considers switch statements, but switch expressions could also have non case labels.

Code Sample demonstrating the issue:

public class Foo {
    void bar(int x) {
        x = switch (x) {
            case 2: int y=8;
            somelabel:  // violation expected
                yield y;
            default:
                int j=8;
                yield j;
        };
    }
}

Expected outcome:

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:false-negativePMD doesn't flag a problematic piece of code

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions