S131 false positive for enhanced switch merged statements

I think this is intended behavior, since if a new enum value is added this code will not do anything and you won’t notice.

Notice that if you do this instead, you no longer get the warning

      var result = switch (pos) {
        case FIRST, SECOND -> doSomething();
        case THIRD -> doSomethingElse();
      };

This is because now that the switch is required to provide a result for all possible branches, you will receive a compile-time error if you add a new enum value but forget to add a corresponding branch.

But if you really want to, you can make this warning go away by explicitly declaring default -> doNothing()

2 Likes