Skip to content

False positive: MissingCasesInEnumSwitch does not recognize an enum-typed type pattern as a catch-all #5798

@findepi

Description

@findepi

Version

2.49.0

Checker

MissingCasesInEnumSwitch

Description

The checker reports MissingCasesInEnumSwitch on a switch with default expressed via a catch-all type pattern (Java 21+)

Reproducer

package repro;

public class Repro {
    enum MyEnum { A, B, C, D }

    String f(MyEnum e) {
        switch (e) {
            case A -> { return "a"; }
            case B -> { return "b"; }
            case MyEnum other -> { return "other: " + other; }
        }
    }
}
[MissingCasesInEnumSwitch] Non-exhaustive switch; either add a default or handle the remaining cases: C, D
        switch (e) {
        ^
    (see https://errorprone.info/bugpattern/MissingCasesInEnumSwitch)

Expected behavior

javac accepts the switch as exhaustive and so should error-prone

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions