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

CompletionFailure in getEnclosingType attaching type annotations

    XMLWordPrintable

Details

    • b11

    Description

      The following example shows a crash in javac while attaching type annotations read from a class file.

      To locate type annotations on class types, javac uses getEnclosingType() to look up enclosing types to interpret type_path_kind=1 entries. The location on inner classes is expressed 'backwards', where an empty path locates the on the 'outermost part of the type for which a type annotation is admissible', and each type_path_kind=1 steps into a nested type.

      For this specific issue, there is enough information in the InnerClasses attribute to determine whether the class type has an enclosing type, so this symbol completion could likely be avoided for classes without an enclosing type.

      In general, completion failures in this code should not trigger a crash. There are a few possible options: report a non-crash error, report a warning (which could be configurable with -Xlint:classfile or another option), or try to silently tolerate the missing information.

      === ./B.java
      import static java.lang.annotation.ElementType.TYPE_USE;

      import java.lang.annotation.Target;

      class B {
        private @Anno A<String> a;

        @Target(TYPE_USE)
        @interface Anno {}
      }
      === ./C.java
      class C {
        B b;
      }
      === ./A.java
      class A<E> {}

      $ javac -fullversion
      javac full version "24-ea+9-972"
      $ javac A.java B.java C.java
      $ rm A.clas
      $ javac C.java -sourcepath : -XDdev
      An exception has occurred in the compiler (24-ea). Please file a bug against the Java compiler via the Java bug reporting page (https://bugreport.java.com) after checking the Bug Database (https://bugs.java.com) for duplicates. Include your program, the following diagnostic, and the parameters passed to the Java compiler in your report. Thank you.
      com.sun.tools.javac.code.Symbol$CompletionFailure: class file for A not found
              at jdk.compiler/com.sun.tools.javac.code.ClassFinder.newCompletionFailure(ClassFinder.java:420)
              at jdk.compiler/com.sun.tools.javac.code.ClassFinder.classFileNotFound(ClassFinder.java:407)
              at jdk.compiler/com.sun.tools.javac.code.ClassFinder.fillIn(ClassFinder.java:402)
              at jdk.compiler/com.sun.tools.javac.code.ClassFinder.complete(ClassFinder.java:302)
              at jdk.compiler/com.sun.tools.javac.code.Symbol.complete(Symbol.java:703)
              at jdk.compiler/com.sun.tools.javac.code.Symbol$ClassSymbol.complete(Symbol.java:1471)
              at jdk.compiler/com.sun.tools.javac.code.Symbol.apiComplete(Symbol.java:709)
              at jdk.compiler/com.sun.tools.javac.jvm.ClassReader$1.getEnclosingType(ClassReader.java:612)
              at jdk.compiler/com.sun.tools.javac.jvm.ClassReader$TypeAnnotationLocator.visitClassType(ClassReader.java:2525)
              at jdk.compiler/com.sun.tools.javac.jvm.ClassReader$TypeAnnotationLocator.visitClassType(ClassReader.java:2501)
              at jdk.compiler/com.sun.tools.javac.code.Type$ClassType.accept(Type.java:1053)
              at jdk.compiler/com.sun.tools.javac.code.Types$DefaultTypeVisitor.visit(Types.java:4920)
              at jdk.compiler/com.sun.tools.javac.jvm.ClassReader$TypeAnnotationSymbolVisitor.addTypeAnnotations(ClassReader.java:2466)

      Attachments

        Issue Links

          Activity

            People

              cushon Liam Miller-Cushon
              cushon Liam Miller-Cushon
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: