-
Notifications
You must be signed in to change notification settings - Fork 786
Open
Description
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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels