-
Bug
-
Resolution: Fixed
-
P3
-
17, 18
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8270222 | 18 | Jan Lahoda | P3 | Resolved | Fixed | b06 |
JDK-8270743 | 17.0.1 | Jan Lahoda | P3 | Resolved | Fixed | b03 |
A DESCRIPTION OF THE PROBLEM :
When using a patterns (a la JEP 406) in a switch statement and a case is empty, it will compile without error, but at runtime, a IncompatibleClassChangeError is thrown upon encountering this line.
The same happens if the case only contains statements that don't happen to be executed when it is reached (e.g. "if (false) return;").
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
run
javac A.java --enable-preview --release 17 && java --enable-preview A
On the provided source code
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
either successful execution and empty output, or a compile-time error
ACTUAL -
Note: A.java uses preview features of Java SE 17.
Note: Recompile with -Xlint:preview for details.
Exception in thread "main" java.lang.IncompatibleClassChangeError
at A.test(A.java:9)
at A.main(A.java:5)
---------- BEGIN SOURCE ----------
sealed interface A permits A.B {
record B() implements A {}
public static void main(String[] args) {
test(new B());
}
static void test(A a) {
switch (a) {
case B b:
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Writing adding "break;" as last statement in the case
When using a patterns (a la JEP 406) in a switch statement and a case is empty, it will compile without error, but at runtime, a IncompatibleClassChangeError is thrown upon encountering this line.
The same happens if the case only contains statements that don't happen to be executed when it is reached (e.g. "if (false) return;").
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
run
javac A.java --enable-preview --release 17 && java --enable-preview A
On the provided source code
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
either successful execution and empty output, or a compile-time error
ACTUAL -
Note: A.java uses preview features of Java SE 17.
Note: Recompile with -Xlint:preview for details.
Exception in thread "main" java.lang.IncompatibleClassChangeError
at A.test(A.java:9)
at A.main(A.java:5)
---------- BEGIN SOURCE ----------
sealed interface A permits A.B {
record B() implements A {}
public static void main(String[] args) {
test(new B());
}
static void test(A a) {
switch (a) {
case B b:
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Writing adding "break;" as last statement in the case
- backported by
-
JDK-8270222 IncompatibleClassChangeError on empty pattern switch statement case
-
- Resolved
-
-
JDK-8270743 IncompatibleClassChangeError on empty pattern switch statement case
-
- Resolved
-