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

javac crashed on call to non-existent generic method with explicit annotated type arg

XMLWordPrintable

    • b02
    • generic
    • generic

      ADDITIONAL SYSTEM INFORMATION :
      Reproduced on macOS Sonoma 14.5 on both x86 and ARM. Java version:

      ```
      > java -version
      openjdk 23-ea 2024-09-17
      OpenJDK Runtime Environment (build 23-ea+27-2275)
      OpenJDK 64-Bit Server VM (build 23-ea+27-2275, mixed mode, sharing)
      ```

      A DESCRIPTION OF THE PROBLEM :
      For the given Test.java source file, javac crashes with an assertion error:
      ```
      > javac -Xdiags:verbose -XDdev -J-XX:+ShowMessageBoxOnError Test.java
      Test.java:10: error: cannot find symbol
          Test.<@Nullable Object>nonNullIdentity(null);
              ^
        symbol: method <Object>nonNullIdentity(<null>)
        location: class Test
      1 error
      An exception has occurred in the compiler (23-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.
      java.lang.ClassCastException: class com.sun.tools.javac.code.Symbol$ClassSymbol cannot be cast to class com.sun.tools.javac.code.Symbol$MethodSymbol (com.sun.tools.javac.code.Symbol$ClassSymbol and com.sun.tools.javac.code.Symbol$MethodSymbol are in module jdk.compiler of loader 'app')
      at jdk.compiler/com.sun.tools.javac.code.TypeAnnotations$TypeAnnotationPositions.resolveFrame(TypeAnnotations.java:1021)
      at jdk.compiler/com.sun.tools.javac.code.TypeAnnotations$TypeAnnotationPositions.resolveFrame(TypeAnnotations.java:996)
      at jdk.compiler/com.sun.tools.javac.code.TypeAnnotations$TypeAnnotationPositions.findPosition(TypeAnnotations.java:1410)
      at jdk.compiler/com.sun.tools.javac.code.TypeAnnotations$TypeAnnotationPositions.visitAnnotatedType(TypeAnnotations.java:1302)
      at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCAnnotatedType.accept(JCTree.java:3090)
      at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:50)
      at jdk.compiler/com.sun.tools.javac.code.TypeAnnotations$TypeAnnotationPositions.scan(TypeAnnotations.java:297)
      at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:58)
      at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.visitApply(TreeScanner.java:253)
      at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1857)
      at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:50)
      at jdk.compiler/com.sun.tools.javac.code.TypeAnnotations$TypeAnnotationPositions.scan(TypeAnnotations.java:297)
      at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.visitExec(TreeScanner.java:226)
      at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCExpressionStatement.accept(JCTree.java:1644)
      at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:50)
      at jdk.compiler/com.sun.tools.javac.code.TypeAnnotations$TypeAnnotationPositions.scan(TypeAnnotations.java:297)
      at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:58)
      at jdk.compiler/com.sun.tools.javac.code.TypeAnnotations$TypeAnnotationPositions.visitBlock(TypeAnnotations.java:1295)
      at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1133)
      at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:50)
      at jdk.compiler/com.sun.tools.javac.code.TypeAnnotations$TypeAnnotationPositions.scan(TypeAnnotations.java:297)
      at jdk.compiler/com.sun.tools.javac.code.TypeAnnotations$TypeAnnotationPositions.visitMethodDef(TypeAnnotations.java:1185)
      at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:957)
      at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:50)
      at jdk.compiler/com.sun.tools.javac.code.TypeAnnotations$TypeAnnotationPositions.scan(TypeAnnotations.java:297)
      at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:58)
      at jdk.compiler/com.sun.tools.javac.code.TypeAnnotations$TypeAnnotationPositions.visitClassDef(TypeAnnotations.java:1115)
      at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:855)
      at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:50)
      at jdk.compiler/com.sun.tools.javac.code.TypeAnnotations$TypeAnnotationPositions.scan(TypeAnnotations.java:297)
      at jdk.compiler/com.sun.tools.javac.code.TypeAnnotations.organizeTypeAnnotationsBodies(TypeAnnotations.java:158)
      at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:5671)
      at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:5526)
      at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:5350)
      at jdk.compiler/com.sun.tools.javac.comp.Attr.attrib(Attr.java:5287)
      at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.attribute(JavaCompiler.java:1355)
      at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:977)
      at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:319)
      at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:178)
      at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:66)
      at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:52)
      ```

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile Test.java as shown above.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      No crash.
      ACTUAL -
      With the diagnostic flags passed you see a stack trace. Without them, you still see a message "printing javac parameters to [path]", indicating a crash occurred.

      ---------- BEGIN SOURCE ----------
      import static java.lang.annotation.ElementType.TYPE_USE;
      import java.lang.annotation.Target;
      class Test {
        @Target(TYPE_USE)
        @interface Nullable {}
        static <T extends @Nullable Object> T identity(T t) {
          return t;
        }
        static void test() {
          Test.<@Nullable Object>nonNullIdentity(null);
          // no crash without the explicit type argument
          //Square.nonNullIdentity(null);
        }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Remove the explicit type argument

      FREQUENCY : always


            vromero Vicente Arturo Romero Zaldivar
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: