Java 12: javac crash with switch expression containing try-catch-finally

Tagir Valeev amaembo at gmail.com
Wed Mar 20 04:10:13 UTC 2019


Hello!

I just wanted to draw your attention to the issue JDK-8220018. I
reported it several weeks ago, but saw no reaction. Probably I failed
to fill all the necessary fields. The problem is still actual in java
12 GA:

// SwTest.java
public class SwTest {
    public static void main(String[] args) {
        System.out.println(switch (0) {
           default -> {
               try {
                   break 1;
               }
               catch (Exception ex) {
                   break 2;
               }
               finally {
                   break 3;
               }
           }
        });
    }
}

C:\Program Files\Java\jdk-12\bin>java.exe -version
openjdk version "12" 2019-03-19
OpenJDK Runtime Environment (build 12+33)
OpenJDK 64-Bit Server VM (build 12+33, mixed mode, sharing)

"C:\Program Files\Java\jdk-12\bin\javac.exe" --enable-preview
--release=12 SwTest.java
Note: SwTest.java uses preview language features.
Note: Recompile with -Xlint:preview for details.
An exception has occurred in the compiler (12). Please file a bug
against the Java compiler via the Java bug reporting page
(http://bugreport.java.com) after checking the Bug Database
(http://bugs.java.com) for duplicates. Include your program and the
following diagnostic in your report. Thank you.
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.jvm.Gen.visitBreak(Gen.java:1707)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBreak.accept(JCTree.java:1561)
at jdk.compiler/com.sun.tools.javac.jvm.Gen.genDef(Gen.java:595)
at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStat(Gen.java:630)
at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStat(Gen.java:616)
at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStats(Gen.java:667)
at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitBlock(Gen.java:1067)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1026)
at jdk.compiler/com.sun.tools.javac.jvm.Gen.genDef(Gen.java:595)
at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStat(Gen.java:630)
at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStat(Gen.java:616)
at jdk.compiler/com.sun.tools.javac.jvm.Gen$3.genLast(Gen.java:1450)

Also similar failure when try-with-resources is used:

import java.util.stream.*;

public class SwTest {
    public static void main(String[] args) {
        System.out.println(switch (0) {
           default -> {
               try(Stream<?> s = Stream.empty()) {
                   break 1;
               }
           }
        });
    }
}

With best regards,
Tagir Valeev.


More information about the compiler-dev mailing list