GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [java] Fix #6984: ExhaustiveSwitchHasDefault: list missing cases in the violation by AzazelSensei · Pull Request #6996 · pmd/pmd

Conversation

@AzazelSensei

@AzazelSensei AzazelSensei commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

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

  • Fix [java] ExhaustiveSwitchHasDefault: Improve violation messages to list missing cases #6984

Ready?

  • Added unit tests for fixed bug/feature
  • Passing all unit tests
  • Complete build ./mvnw clean verify passes (checked automatically by github actions)
  • Added (in-code) documentation (if needed)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@AzazelSensei AzazelSensei mentioned this pull request Aug 25, 2026
[java] ExhaustiveSwitchHasDefault: Improve violation messages to list missing cases #6984
Closed
@pmd-actions-helper

pmd-actions-helper Bot commented Aug 25, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Documentation Preview

Compared to main:
This changeset changes 91 violations,
introduces 0 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 16 errors and 9 configuration errors.
There are 0 changed duplications, 0 new duplications and 0 removed duplications.
There are 0 changed CPD errors, 0 new CPD errors and 0 removed CPD errors.

Regression Tester Report

(comment created at 2026-10-18 15:30:01+00:00 for b787944)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@zbynek

zbynek commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

By checking the regressionreport it's obvious there are multiple cases that need different messages:

  • switch expression where some cases are covered by the default branch
    • here "Replace default case with explicit cases (...) to make sure compiler keeps checking that all cases are present." message makes sense
  • switch expression where the default branch covers 0 cases
    • if arrow branches are used, it would be better to say "Remove default case to make sure compiler keeps checking that all cases are present. "
    • if old-style branches (using colon) are used, the default branch cannot be removed -- should this special case be reported at all?
  • switch statement where some cases are covered by the default branch
    • here it's not true that compiler checks anything -- however it's still good to replace default with explicit values and use NonExhaustiveSwitch PMD rule to make sure the list stays exhaustive
  • switch statement where the default branch covers 0 cases
    • again, the compiler does not check anything, so removing the default branch is only safe if NonExhaustiveSwitch rule is active
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@AzazelSensei
[java] ExhaustiveSwitchHasDefault: list missing cases in the violation
8846018
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
@AzazelSensei
AzazelSensei force-pushed the fix/exhaustive-switch-message-6984 branch from 046992b to 8846018 Compare August 30, 2026 17:57
@AzazelSensei

AzazelSensei commented Aug 30, 2026

Copy link
Copy Markdown
Contributor Author

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

UncleOwen
UncleOwen reviewed Sep 7, 2026
View reviewed changes
Comment thread ...in/java/net/sourceforge/pmd/lang/java/rule/bestpractices/ExhaustiveSwitchHasDefaultRule.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

@AzazelSensei
[java] ExhaustiveSwitchHasDefault: add tests for missingCases
9859997
The helper was package-private for tests; cover enum, sealed, fully
covered, and non-class selectors.
@UncleOwen

UncleOwen commented Sep 30, 2026

Copy link
Copy Markdown
Member

@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?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

zbynek
zbynek reviewed Sep 30, 2026
View reviewed changes
Comment thread ...esources/net/sourceforge/pmd/lang/java/rule/bestpractices/xml/ExhaustiveSwitchHasDefault.xml Outdated
<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>

@zbynek zbynek Sep 30, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this one the suggestion should be also "remove" rather than "replace" and it should not mention compiler checks.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

adangel reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@adangel adangel Oct 18, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll replace the message with "Remove default case and use the rule NonExhaustiveSwitch to make sure the switch stays exhaustive."

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
adangel added 3 commits October 18, 2026 16:01
@adangel
Merge branch 'main' into pr-6996
b982c37
@adangel
Reformat test cases for better readability
38fba1d
@adangel
Better rule message for switch statements
b787944
The rule NonExhaustiveSwitch should be used
to make sure the switch stays exhaustive.
adangel
adangel reviewed Oct 18, 2026
View reviewed changes

@adangel adangel left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. I'll update the message (remove the compiler check hint for switch statements) and merge, if it looks ok.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread ...esources/net/sourceforge/pmd/lang/java/rule/bestpractices/xml/ExhaustiveSwitchHasDefault.xml Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread ...esources/net/sourceforge/pmd/lang/java/rule/bestpractices/xml/ExhaustiveSwitchHasDefault.xml Outdated
<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>

@adangel adangel Oct 18, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll replace the message with "Remove default case and use the rule NonExhaustiveSwitch to make sure the switch stays exhaustive."

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@adangel adangel added this to the 7.29.0 milestone Oct 18, 2026
adangel
adangel approved these changes Oct 18, 2026
View reviewed changes
@adangel adangel changed the title [java] ExhaustiveSwitchHasDefault: list missing cases in the violation [java] Fix #6984: ExhaustiveSwitchHasDefault: list missing cases in the violation Oct 18, 2026
@adangel
adangel merged commit 128db42 into pmd:main Oct 18, 2026
13 checks passed

Uh oh!

There was an error while loading. Please reload this page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@zbynek zbynek zbynek left review comments
@UncleOwen UncleOwen UncleOwen left review comments
@adangel adangel adangel approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

7.29.0

Development

Successfully merging this pull request may close these issues.

[java] ExhaustiveSwitchHasDefault: Improve violation messages to list missing cases

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@AzazelSensei @zbynek @UncleOwen @adangel
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.