Skip to content

[java] ExhaustiveSwitchHasDefault/NonExhaustiveSwitch Support future-proofing switch statements against added enum members #6879

Open

Description

@UncleOwen

Maybe another detail to consider.

Even if you have an a classical switch statement with all cases for an enum plus a default case, the rule mentioned here should not throw if the default case is just throwing an exception.

Maybe even the NonEhaustiveSwitch rule should be enhanced to have a finding if you have an exhaustive switch statement without throwing default case.

If you have a switch statement over an enum that you compile along with the switch statement, you can ensure the branches at compile time.

But if you for example switch over an enum from a different artifact, then at runtime that other artifact could be of a different version and thus there can be more enum constants available, so a default case that throws makes sense to detect this.

If this is added, it would also be questionable whether the NonEhaustiveSwitch should consider a switch statement with not all constants but a throwing default as excaustive already or not.

Maybe it should not be "default case that throws" but "default case that throws AssertionError", so that you can identify the runtime-exhaustiveness-protection default branch from a default branch that intentionally throws an excepetion for other enum-cases.

Originally posted by @Vampire in #5514

Activity

  1. added
    an:enhancement
    on Jul 15, 2026
  2. changed the title [-][java] ExhaustiveSwitchHasDefault/NonEhaustiveSwitch Support future-proofing switch statements against added enum members[/-] [+][java] ExhaustiveSwitchHasDefault/NonExhaustiveSwitch Support future-proofing switch statements against added enum members[/+] on Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    an:enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions