Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8257740

Compiler crash when compiling type annotation on multicatch inside lambda

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 9, 11, 15, 16
    • Fix Version/s: 17
    • Component/s: tools
    • Labels:
      None
    • Subcomponent:
    • Introduced In Version:
      9
    • Resolved In Build:
      b05

      Description

      Here's the minimal example:

      import java.lang.annotation.ElementType;
      import java.lang.annotation.Target;

      public class Test {
        @Target(ElementType.TYPE_USE)
        @interface Anno {}
        
        void test() {
          Runnable r = () -> {
            try {
              System.out.println();
            } catch (@Anno Error | RuntimeException e) {
              e.printStackTrace();
            }
          };
        }
      }

      I see the following exception during the compilation:

      An exception has occurred in the compiler (16-ea). Please file a bug against the Java compiler via the Java bug reporting page (http://bugre
      port.java.com) after checking the Bug Database (http://bugs.java.com) for duplicates. Include your program, the following diagnostic, and th
      e parameters passed to the Java compiler in your report. Thank you.
      java.lang.AssertionError: exception_index is not set
              at jdk.compiler/com.sun.tools.javac.util.Assert.error(Assert.java:162)
              at jdk.compiler/com.sun.tools.javac.util.Assert.check(Assert.java:95)
              at jdk.compiler/com.sun.tools.javac.code.TypeAnnotationPosition.getExceptionIndex(TypeAnnotationPosition.java:307)
              at jdk.compiler/com.sun.tools.javac.jvm.ClassWriter.writePosition(ClassWriter.java:677)
              at jdk.compiler/com.sun.tools.javac.jvm.ClassWriter.writeTypeAnnotation(ClassWriter.java:648)
              at jdk.compiler/com.sun.tools.javac.jvm.ClassWriter.writeTypeAnnotations(ClassWriter.java:561)
              at jdk.compiler/com.sun.tools.javac.jvm.ClassWriter.writeCode(ClassWriter.java:1119)
              at jdk.compiler/com.sun.tools.javac.jvm.ClassWriter.writeMethod(ClassWriter.java:987)
              at jdk.compiler/com.sun.tools.javac.jvm.ClassWriter.writeMethods(ClassWriter.java:1478)
              at jdk.compiler/com.sun.tools.javac.jvm.ClassWriter.writeClassFile(ClassWriter.java:1583)
              at jdk.compiler/com.sun.tools.javac.jvm.ClassWriter.writeClass(ClassWriter.java:1504)
              at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.genCode(JavaCompiler.java:757)
              at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.generate(JavaCompiler.java:1644)
              at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.generate(JavaCompiler.java:1612)
              at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:973)
              at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:317)
              at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:176)
              at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:64)
              at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:50)

      Tried javac versions:
      build 9+181
      build 11+28
      build 15+36-1562
      build 16-ea+27-1884
      The behavior is the same

      Can be correctly compiled in build 1.8.0_232-b09 and build 1.8.0_252-b09. So I assume the regression was introduced in Java 9.

      It looks like that all components of this test are important: lambda, multi-catch, type-use annotation. Removing either of them results in a successful compilation.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              vromero Vicente Arturo Romero Zaldivar
              Reporter:
              tvaleev Tagir Valeev
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: