In the following example, the check UnnecessaryDefaultInEnumSwitch suggests to remove the default clause with the reason "Switch handles all enum values: the default case can be omitted to enable enforcement at compile-time that the switch statement is exhaustive." But the code would not compile then:
public class Test {
enum TestEnum {
FOO,
BAR;
}
void unnecessaryDefault() {
String x;
switch (TestEnum.FOO) {
case FOO -> x = "FOO";
case BAR -> x = "BAR";
default -> throw new AssertionError();
}
System.out.println(x);
}
}
It seems the reason is the incomplete handling of arrow rules from e5d52dd in
|
List<? extends StatementTree> defaultStatements = defaultCase.getStatements(); |
|
if (defaultStatements == null) { |
|
// TODO(b/177258673): provide fixes for `case -> ...` |
|
return buildDescription(defaultCase).setMessage(DESCRIPTION_REMOVED_DEFAULT).build(); |
|
} |
In the following example, the check UnnecessaryDefaultInEnumSwitch suggests to remove the
defaultclause with the reason "Switch handles all enum values: the default case can be omitted to enable enforcement at compile-time that the switch statement is exhaustive." But the code would not compile then:It seems the reason is the incomplete handling of arrow rules from e5d52dd in
error-prone/core/src/main/java/com/google/errorprone/bugpatterns/UnnecessaryDefaultInEnumSwitch.java
Lines 159 to 163 in cecce2e