You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[java] ExhaustiveSwitchHasDefault: Improve violation messages to list missing cases #6984
The switch below is not exhaustive. NEW is only handled by default. Yet PMD reports "exhaustive even without the default case". Removing default produces a compile error (the switch expression does not cover all possible input values).
No, this isn't a false positive. "Exhaustive" in this context doesn't mean "all possible cases are there" but "the compiler can check whether all possible cases are there". See the rule's description.
But I agree that the violation message could be improved.
changed the title [-][java] ExhaustiveSwitchHasDefault false positive when enum switch has "case null"[/-][+][java] ExhaustiveSwitchHasDefault improve violation message[/+]on Aug 19, 2026
The first one is very abstract. I like your second suggestion, especially that is mentions that this is about sealed types - but maybe try to make "safety net" more explicit?
Maybe the rule could be rewritten in Java and the error message enhanced to list the enum constants / sealed interface implementations that are needed to replace default?
"A default case in a switch on sealed classes or enums prevents the compiler from checking that all cases are present."
@zbynek It's already a java rule in current main :) Could you give an example of how this would look like? Just "(missing case: NEW)" added to whatever the new message is?
changed the title [-][java] ExhaustiveSwitchHasDefault improve violation message[/-][+][java] ExhaustiveSwitchHasDefault: Improve violation message to list missing cases[/+]on Oct 18, 2026
changed the title [-][java] ExhaustiveSwitchHasDefault: Improve violation message to list missing cases[/-][+][java] ExhaustiveSwitchHasDefault: Improve violation messages to list missing cases[/+]on Oct 29, 2026
Activity
UncleOwen commentedon Aug 18, 2026
No, this isn't a false positive. "Exhaustive" in this context doesn't mean "all possible cases are there" but "the compiler can check whether all possible cases are there". See the rule's description.
But I agree that the violation message could be improved.
armandino commentedon Aug 19, 2026
@UncleOwen thank you for clarifying. Couple of options for the error message if there's interest in updating it (happy to submit a PR):
[-][java] ExhaustiveSwitchHasDefault false positive when enum switch has "case null"[/-][+][java] ExhaustiveSwitchHasDefault improve violation message[/+]UncleOwen commentedon Aug 19, 2026
The first one is very abstract. I like your second suggestion, especially that is mentions that this is about sealed types - but maybe try to make "safety net" more explicit?
PRs are definitely welcome!
zbynek commentedon Aug 19, 2026
Maybe the rule could be rewritten in Java and the error message enhanced to list the enum constants / sealed interface implementations that are needed to replace
default?armandino commentedon Aug 20, 2026
Other alternatives:
UncleOwen commentedon Aug 20, 2026
I was thinking something like
"A default case in a switch on sealed classes or enums prevents the compiler from checking that all cases are present."
@zbynek It's already a java rule in current main :) Could you give an example of how this would look like? Just "(missing case: NEW)" added to whatever the new message is?
zbynek commentedon Aug 20, 2026
I was thinking something like
"Replace default case with explicit cases (NEW) to make sure compiler keeps checking that all cases are present."
UncleOwen commentedon Aug 20, 2026
I like it!
armandino commentedon Aug 21, 2026
Should it truncate the list if a failure has too many values to report?
UncleOwen commentedon Aug 21, 2026
Yes!
AzazelSensei commentedon Aug 25, 2026
Opened #6996. The message now lists the missing cases and truncates after three.
[java] ExhaustiveSwitchHasDefault: list missing cases in the violation
[-][java] ExhaustiveSwitchHasDefault improve violation message[/-][+][java] ExhaustiveSwitchHasDefault: Improve violation message to list missing cases[/+][java] Fix pmd#6984: ExhaustiveSwitchHasDefault: list missing cases i…
[-][java] ExhaustiveSwitchHasDefault: Improve violation message to list missing cases[/-][+][java] ExhaustiveSwitchHasDefault: Improve violation messages to list missing cases[/+]