Skip to content

False Positive : Non-fall-through switch branches are still reported #5671

@Carlson-JLQ

Description

@Carlson-JLQ

False Positive : Non-fall-through switch branches are still reported

Affects errorprone Version:

2.48.0

Checker:

FallThrough

Description:

According to the official FallThrough documentation, a warning is only appropriate when one switch statement group can continue into the next without terminating abruptly and without an intentional fall-through comment. The following samples all terminate the earlier branch with break, return, or throw, so no fall-through is possible.

Code Sample demonstrating the issue:

// NegCase1
switch (x) {
    case 1:
        System.out.println("Case 1");
        break;
    case 2:
        System.out.println("Case 2");
        break;
}

// PMD NegCase3
switch (x) {
    case 1:
        System.out.println("Case 1");
        return;
    case 2:
        System.out.println("Case 2");
        break;
    default:
        break;
}

// PMD NegCase1
switch (x) {
    case 1:
        System.out.println("Case 1");
        break;
    case 2:
        System.out.println("Case 2");
        return;
    case 3:
        System.out.println("Case 3");
        throw new RuntimeException();
    case 4:
        throw new RuntimeException();
    default:
        System.out.println("Default");
}

Each branch above already terminates abruptly, so execution cannot reach the next statement group. Reporting these cases as missing fall-through comments would contradict the checker's own documented condition.

Expected outcome:

Error Prone should not report a FallThrough warning for these switch branches, but it does. This is a false-positive.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions