JDK-8309336 : Incorrect switch in enum not reported properly
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2023-06-02
  • Updated: 2023-06-13
  • Resolved: 2023-06-05
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 21
21 b26Fixed
Related Reports
Relates :  
Description
Consider code like:
```
public class QualEnum {
    private void test(E e) {
        switch (e) {
            case ea -> {}
            default -> {}
        }
    }
    static final E ea = E.A;
    enum E {A}
}
```

This should fail to compile with a proper compile-time error, but it crashes javac:
```
java.lang.AssertionError
	at jdk.compiler/com.sun.tools.javac.util.Assert.error(Assert.java:155)
	at jdk.compiler/com.sun.tools.javac.util.Assert.check(Assert.java:46)
	at jdk.compiler/com.sun.tools.javac.comp.Lower$CompileTimeEnumMapping.caseValue(Lower.java:505)
	at jdk.compiler/com.sun.tools.javac.comp.Lower.visitEnumSwitch(Lower.java:3866)
...
```

Comments
Changeset: 05fb6c66 Author: Jan Lahoda <jlahoda@openjdk.org> Date: 2023-06-05 06:25:00 +0000 URL: https://git.openjdk.org/jdk/commit/05fb6c6648bc759853c5a9c5b932706592d87ba9
05-06-2023

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/14284 Date: 2023-06-02 12:47:08 +0000
02-06-2023