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 — UnnecessaryDefaultInEnumSwitch provides illegal suggestion for arrow rules in switch statements · Issue #5045 · google/error-prone

UnnecessaryDefaultInEnumSwitch provides illegal suggestion for arrow rules in switch statements #5045

New issue
Copy link
New issue
Copy link
Closed
Closed
UnnecessaryDefaultInEnumSwitch provides illegal suggestion for arrow rules in switch statements#5045
Copy link

Description

@PhilippWendler
PhilippWendler
opened on May 12, 2025
Issue body actions

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

error-prone/core/src/main/java/com/google/errorprone/bugpatterns/UnnecessaryDefaultInEnumSwitch.java

Lines 159 to 163 in cecce2e

List<? extends StatementTree> defaultStatements = defaultCase.getStatements();
if (defaultStatements == null) {
// TODO(b/177258673): provide fixes for `case -> ...`
return buildDescription(defaultCase).setMessage(DESCRIPTION_REMOVED_DEFAULT).build();
}

Activity

  1. PhilippWendler
    added a commit that references this issue on May 12, 2025

    Remove default clauses of switch statements that are redundant

    8be123f
  2. copybara-service
    added 3 commits that reference this issue on May 13, 2025

    Handle `->` switches some more in UnnecessaryDefaultInEnumSwitch, usi…

    4f0dcd6

    Handle `->` switches some more in UnnecessaryDefaultInEnumSwitch, usi…

    832307a

    Handle `->` switches some more in UnnecessaryDefaultInEnumSwitch, usi…

    2c9e2fe
  3. graememorgan commented on May 21, 2025

    @graememorgan
    graememorgan
    on May 21, 2025
    Contributor
    More actions

    Thanks for the report. We had a TODO to improve handling around this, and hopefully it's now TODONE. :)

  4. graememorgan
    closed this as completedon May 21, 2025
  5. svc-squareup-copybara
    added a commit that references this issue on Jun 26, 2025

    This PR contains the following updates:

    089d991
  6. swear01
    added a commit that references this issue on May 26, 2026

    Remove default clauses of switch statements that are redundant

    b42fd99
  7. eizus
    added a commit that references this issue on Jul 18, 2026

    This PR contains the following updates:

    d285a3b
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      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.