[pattern-switch] Exhaustiveness

Dan Smith daniel.smith at oracle.com
Mon Aug 31 23:00:03 UTC 2020


> On Aug 31, 2020, at 9:09 AM, Brian Goetz <brian.goetz at oracle.com> wrote:
> 
> To be clear, I think the sweet spot here is:
> 
>  - Legacy enum, string, and box (ESB) switches continue to throw NPE on null;
>  - Total switches on enum (including the current expression switches on enum) throw ICCE on a novel value; 
>  - For new switches with remainder: 
>    - Continue to throw NPE on unhandled null remainder;
>    - Throw UnexpectedFrogException on any other unhandled remainder.

I'm still thinking it's worthwhile to change the behavior of enum switches to throw the same thing as sealed class switches.

Two reasons:

- ICCE is arguably just wrong. It's not an incompatible change to add an enum constant to an enum declaration.

- The inconsistency is a risk—somebody thinks they're catching the exception, then they discover, oops, enum switches throw a different exception type for historical reasons.

Of course, behavioral changes are a risk, too, but I think getting it in early, before there's been much time for adoption of switch expressions and evolution of enums, minimizes that risk. (We could even make the change in 16 as a spec bug fix.)



More information about the amber-spec-experts mailing list