Closed forax closed 3 weeks ago
Thanks for the report Rémi. Reproduced.
Smaller test case:
public sealed interface X permits X.R {
record R(String s) implements X {}
public static void add(X x) {
switch (x) {
case R r:
if (r.s == null) {
throw new NullPointerException();
}
}
}
public static void main(String[] args) {
add(new R("bar"));
}
}
Problem dates back to 4.30
Same underlying problem as https://github.com/eclipse-jdt/eclipse.jdt.core/issues/2513 - the proposed fix there was using too much local context. That deficiency should be addressed by the current PR https://github.com/eclipse-jdt/eclipse.jdt.core/pull/3098
To check and to address separately if needed: whether JDK18- code falls into the compiler inserted default that throws an IncompatibleClassChangeError
To check and to address separately if needed: whether JDK18- code falls into the compiler inserted default that throws an
IncompatibleClassChangeError
Yes, this scenario is correctly handled. I have added more tests here: https://github.com/eclipse-jdt/eclipse.jdt.core/pull/3099
Hello, One of my TA has found the following bug, if a switch is exhautive, i.e. the cases cover all subtypes of the sealed interface, as the JLS says the compiler adds a
default -> throw new MatchException();
and a break is added in the last case if necessary.Here Eclipse fails to properly analyze the
if (bs == null)
so it does not insert the break after the last case so at runtime, the case B fallthrough and throws a MatchException.