JDK-8337998 : CompletionFailure in getEnclosingType attaching type annotations
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2024-08-07
  • Updated: 2025-04-18
  • Resolved: 2024-08-13
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 JDK 23 JDK 24
21.0.8Fixed 23.0.2Fixed 24 b11Fixed
Related Reports
Relates :  
Relates :  
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)
Comments
OpenJDK 21u maintainer comment: Note that JDK-8341779 (new in 21.0.8) is a redo of the 21 backport of JDK-8225377 which got backed out in 21.0.2.
18-04-2025

A pull request was submitted for review. Branch: master URL: https://git.openjdk.org/jdk21u-dev/pull/1253 Date: 2024-12-17 22:35:00 +0000
17-04-2025

[jdk21u-fix-request] Approval Request from Liam Miller-Cushon for backport. This is a follow-on fix related to the backport of JDK-8341779 (allow accessing type-use annotations on types loaded from class files), if that backport is approved this change should also be backported. Tested with tier1.
27-03-2025

A pull request was submitted for review. Branch: master URL: https://git.openjdk.org/jdk23u/pull/68 Date: 2024-08-13 17:29:20 +0000
13-08-2024

[jdk23u-fix-request] Approval Request from Liam Miller-Cushon This change fixes a javac crash when classes are missing from the classpath. The fix causes javac to instead report a non-crash error diagnostic. The patch applies cleanly, and langtools tier1 passes.
13-08-2024

Changeset: 9e282e5c Branch: master Author: Liam Miller-Cushon <cushon@openjdk.org> Date: 2024-08-13 15:05:49 +0000 URL: https://git.openjdk.org/jdk/commit/9e282e5c966a9c065de8b901b7d30bb5c9ccf243
13-08-2024

A pull request was submitted for review. Branch: master URL: https://git.openjdk.org/jdk/pull/20495 Date: 2024-08-07 15:59:58 +0000
07-08-2024