[jdk17] Integrated: 8270151: IncompatibleClassChangeError on empty pattern switch statement case

Maurizio Cimadamore mcimadamore at openjdk.java.net
Fri Jul 9 11:07:20 UTC 2021

On Fri, 9 Jul 2021 10:00:06 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:

> Consider code like:
> sealed interface I {}
> final class A implements I {}
> ...
> I i = null;
> switch (i) {
>      case A a:
> }
> The switch is exhaustive, and javac must generate a synthetic default clause throwing an `IncompatibleClassChangeError` for the case where the permitted classes for I changes. The default clause is generated at the end of the switch statement, and consequently the execution will fall through from `case A a:` to this synthetic default, causing the `IncompatibleClassChangeError` for a valid input. (Note this was not a problem for switch expressions, as the last case can never complete normally for a switch expression.)
> This PR proposes to put the synthetic default at the beginning of the switch statement, rather than at the end, which should avoid fall-through issues. An alternative solution would be to generate a synthetic break into the last case, but that is a bit tricky, so placing the default at the beginning seems more reliable to me.

Looks good!


Marked as reviewed by mcimadamore (Reviewer).

PR: https://git.openjdk.java.net/jdk17/pull/237

More information about the compiler-dev mailing list