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

Jan Lahoda jlahoda at openjdk.java.net
Fri Jul 9 11:07:21 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.

This pull request has now been integrated.

Changeset: 1196b356
Author:    Jan Lahoda <jlahoda at openjdk.org>
URL:       https://git.openjdk.java.net/jdk17/commit/1196b3568459511df7534848ac42f13489c61be6
Stats:     24 lines in 3 files changed: 21 ins; 0 del; 3 mod

8270151: IncompatibleClassChangeError on empty pattern switch statement case

Reviewed-by: mcimadamore

-------------

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


More information about the compiler-dev mailing list