JDK-8054975 : Type annotation on catch parameter
  • Type: Sub-task
  • Component: tools
  • Sub-Component: javac
  • Priority: P3
  • Status: Open
  • Resolution: Unresolved
  • Submitted: 2014-08-13
  • Updated: 2016-07-28
Description
A fellow Checker Framework developer recently discovered an issue
(https://code.google.com/p/checker-framework/issues/detail?id=344)
that can be reproduced with trunk jdk9:

===
import java.lang.annotation.*;

class TestIssue344 {
    public void foo() {
        try {
            return;
        } catch (@TA Exception e) {
        }
    }
}

@Target(ElementType.TYPE_USE)
@interface TA {}
====

Compiling this file results in:

An exception has occurred in the compiler (1.9.0-internal). Please
file a bug at the Java Developer Connection
(http://java.sun.com/webapps/bugreport)  after checking the Bug Parade
for duplicates. Include your program and the following diagnostic in
your report.  Thank you.
java.lang.AssertionError: Could not find exception index for type
annotation @TA on exception parameter
at com.sun.tools.javac.util.Assert.error(Assert.java:132)
at com.sun.tools.javac.jvm.Code.fillExceptionParameterPositions(Code.java:2157)
at com.sun.tools.javac.jvm.Gen.genMethod(Gen.java:964)
at com.sun.tools.javac.jvm.Gen.visitMethodDef(Gen.java:872)
at com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:814)
at com.sun.tools.javac.jvm.Gen.genDef(Gen.java:615)
at com.sun.tools.javac.jvm.Gen.genClass(Gen.java:2385)
at com.sun.tools.javac.main.JavaCompiler.genCode(JavaCompiler.java:741)
at com.sun.tools.javac.main.JavaCompiler.generate(JavaCompiler.java:1578)
at com.sun.tools.javac.main.JavaCompiler.generate(JavaCompiler.java:1542)
at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:897)
at com.sun.tools.javac.main.Main.compile(Main.java:536)
at com.sun.tools.javac.main.Main.compile(Main.java:383)
at com.sun.tools.javac.main.Main.compile(Main.java:372)
at com.sun.tools.javac.main.Main.compile(Main.java:363)
at com.sun.tools.javac.Main.compile(Main.java:56)
at com.sun.tools.javac.Main.main(Main.java:42)

This issue does not occur in the jdk8 version.
Comments
Removing "return" in try block makes code compilable.
22-10-2014

ILW: H (Crash), L (uncommon use case), M (update source) -> P3
19-09-2014