Repository navigation
[java] Fix #6984: ExhaustiveSwitchHasDefault: list missing cases in the violation - #6996
Conversation
|
Compared to main: (comment created at 2026-10-18 15:30:01+00:00 for b787944) |
|
By checking the regressionreport it's obvious there are multiple cases that need different messages:
|
The old message said the switch was already exhaustive. That hid the constants still only handled by default. UncleOwen asked for the missing names, truncated after three. Fixes pmd#6984
046992b to
8846018
Compare
|
Rebased onto main. Arrow switch expressions with no missing constants now say to remove the default. Colon-style branches and switch statements still use the original message — those look like a separate call on whether to report them. |
The helper was package-private for tests; cover enum, sealed, fully covered, and non-class selectors.
|
@zbynek What do you think about this one? I think the message for the other cases should be changed as well. Maybe "... so that NonExhaustiveSwitch can check them" for the cases where the compiler doesn't check them? |
| <expected-problems>1</expected-problems> | ||
| <expected-linenumbers>6</expected-linenumbers> | ||
| <expected-messages> | ||
| <message>Replace default case with explicit cases to make sure compiler keeps checking that all cases are present.</message> |
There was a problem hiding this comment.
For this one the suggestion should be also "remove" rather than "replace" and it should not mention compiler checks.
There was a problem hiding this comment.
I'll replace the message with "Remove default case and use the rule NonExhaustiveSwitch to make sure the switch stays exhaustive."
The rule NonExhaustiveSwitch should be used to make sure the switch stays exhaustive.
adangel
left a comment
There was a problem hiding this comment.
Thanks for the PR. I'll update the message (remove the compiler check hint for switch statements) and merge, if it looks ok.
| <expected-problems>1</expected-problems> | ||
| <expected-linenumbers>6</expected-linenumbers> | ||
| <expected-messages> | ||
| <message>Replace default case with explicit cases to make sure compiler keeps checking that all cases are present.</message> |
There was a problem hiding this comment.
I'll replace the message with "Remove default case and use the rule NonExhaustiveSwitch to make sure the switch stays exhaustive."
Describe the PR
ExhaustiveSwitchHasDefault used to say the switch was exhaustive even without default. That read like a false positive when a constant (NEW in the issue) only lived in
default.The message is now:
Replace default case with explicit cases (NEW) to make sure compiler keeps checking that all cases are present.
If nothing is missing, the parenthetical is dropped. More than three names get truncated with
....Related issues
Ready?
./mvnw clean verifypasses (checked automatically by github actions)