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

Jan Lahoda jlahoda at openjdk.java.net
Fri Jul 9 11:07:20 UTC 2021


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.

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

Commit messages:
 - Generate synthetic breaks at the beginning of switches rather than at the end, to avoid issues if the statements in the last case complete normally.

Changes: https://git.openjdk.java.net/jdk17/pull/237/files
 Webrev: https://webrevs.openjdk.java.net/?repo=jdk17&pr=237&range=00
  Issue: https://bugs.openjdk.java.net/browse/JDK-8270151
  Stats: 24 lines in 3 files changed: 21 ins; 0 del; 3 mod
  Patch: https://git.openjdk.java.net/jdk17/pull/237.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk17 pull/237/head:pull/237

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


More information about the compiler-dev mailing list