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

"AssertionError: Could not determine position of tree ... " for anonymous class

XMLWordPrintable

    • x86_64
    • windows_10

      ADDITIONAL SYSTEM INFORMATION :
      JDK 8 update 162 (1.8.0_162).
      Windows 10 x64.

      A DESCRIPTION OF THE PROBLEM :
      An assertion error occurs when compiling an anonymous class declaration/instantiation with javac, where:
      (1) The anonymous class extends an inner class,
      (2) The type of the inner class is annotated in the instantiation, and
      (3) An enclosing expression is provided.
      For example "instance.new @MyAnno OuterClass.InnerClass() { ... }".

      The specific error is:
      "java.lang.AssertionError: Could not determine position of tree @MyAnno InnerClass within frame new @MyAnno InnerClass(<*nullchk*>instance){
          
          (.OuterClass x0) {
              x0.super();
          }
      }", which is thrown at TypeAnnotations.java:707.

      The problem does not occur in JDK9 and was fixed at this commit: (http://hg.openjdk.java.net/jdk9/dev/langtools/annotate/62e285806e83/src/jdk.compiler/share/classes/com/sun/tools/javac/code/TypeAnnotations.java#l725) but using the javac provided with JDK9 is not currently a suitable workaround when custom annotation processors (such as Checker Framework) are used, which are not yet compatible with JDK9.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile the provided source code using javac.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The compilation completes successfully.
      ACTUAL -
      An exception has occurred in the compiler (1.8.0_162). Please file a bug against the Java compiler via the Java bug reporting page (http://bugreport.java.com) after checking the Bug Database (http://bugs.java.com) for duplicates. Include your program and the following diagnostic in your report. Thank you.
      java.lang.AssertionError: Could not determine position of tree @MyAnno InnerClass within frame new @MyAnno InnerClass(<*nullchk*>instance){

          (.OuterClass x0) {
              x0.super();
          }
      }
              at com.sun.tools.javac.util.Assert.error(Assert.java:133)
              at com.sun.tools.javac.code.TypeAnnotations$TypeAnnotationPositions.resolveFrame(TypeAnnotations.java:707)
              at com.sun.tools.javac.code.TypeAnnotations$TypeAnnotationPositions.resolveFrame(TypeAnnotations.java:933)
              at com.sun.tools.javac.code.TypeAnnotations$TypeAnnotationPositions.findPosition(TypeAnnotations.java:1331)
              at com.sun.tools.javac.code.TypeAnnotations$TypeAnnotationPositions.visitAnnotatedType(TypeAnnotations.java:1213)
              at com.sun.tools.javac.tree.JCTree$JCAnnotatedType.accept(JCTree.java:2373)
              at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
              at com.sun.tools.javac.code.TypeAnnotations$TypeAnnotationPositions.scan(TypeAnnotations.java:275)
              at com.sun.tools.javac.code.TypeAnnotations$TypeAnnotationPositions.visitNewClass(TypeAnnotations.java:1267)
              at com.sun.tools.javac.tree.JCTree$JCNewClass.accept(JCTree.java:1516)
              at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
              at com.sun.tools.javac.code.TypeAnnotations$TypeAnnotationPositions.scan(TypeAnnotations.java:275)
              at com.sun.tools.javac.tree.TreeScanner.visitExec(TreeScanner.java:175)
              at com.sun.tools.javac.tree.JCTree$JCExpressionStatement.accept(JCTree.java:1296)
              at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
              at com.sun.tools.javac.code.TypeAnnotations$TypeAnnotationPositions.scan(TypeAnnotations.java:275)
              at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:57)
              at com.sun.tools.javac.code.TypeAnnotations$TypeAnnotationPositions.visitBlock(TypeAnnotations.java:1206)
              at com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:909)
              at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
              at com.sun.tools.javac.code.TypeAnnotations$TypeAnnotationPositions.scan(TypeAnnotations.java:275)
              at com.sun.tools.javac.code.TypeAnnotations$TypeAnnotationPositions.visitMethodDef(TypeAnnotations.java:1107)
              at com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:778)
              at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
              at com.sun.tools.javac.code.TypeAnnotations$TypeAnnotationPositions.scan(TypeAnnotations.java:275)
              at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:57)
              at com.sun.tools.javac.code.TypeAnnotations$TypeAnnotationPositions.visitClassDef(TypeAnnotations.java:1042)
              at com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:693)
              at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
              at com.sun.tools.javac.code.TypeAnnotations$TypeAnnotationPositions.scan(TypeAnnotations.java:275)
              at com.sun.tools.javac.code.TypeAnnotations.organizeTypeAnnotationsBodies(TypeAnnotations.java:155)
              at com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:4394)
              at com.sun.tools.javac.comp.Attr.attribClass(Attr.java:4272)
              at com.sun.tools.javac.comp.Attr.attribClass(Attr.java:4201)
              at com.sun.tools.javac.comp.Attr.attrib(Attr.java:4176)
              at com.sun.tools.javac.main.JavaCompiler.attribute(JavaCompiler.java:1248)
              at com.sun.tools.javac.main.JavaCompiler.compile2(JavaCompiler.java:901)
              at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:860)
              at com.sun.tools.javac.main.Main.compile(Main.java:523)
              at com.sun.tools.javac.main.Main.compile(Main.java:381)
              at com.sun.tools.javac.main.Main.compile(Main.java:370)
              at com.sun.tools.javac.main.Main.compile(Main.java:361)
              at com.sun.tools.javac.Main.compile(Main.java:56)
              at com.sun.tools.javac.Main.main(Main.java:42)


      ---------- BEGIN SOURCE ----------
      =====
      import java.lang.annotation.ElementType;
      import java.lang.annotation.Retention;
      import java.lang.annotation.RetentionPolicy;
      import java.lang.annotation.Target;

      @Retention(RetentionPolicy.RUNTIME)
      @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
      public @interface MyAnno {
      }

      ====
      public class OuterClass {
      public class InnerClass {
      }

      public void doSomething(OuterClass instance) {
      instance.new @MyAnno InnerClass() { };
      }
      }
      ====
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      While the javac in JDK9 does not have this issue, it is not a suitable workaround where custom annotation processing tools (e.g. Checker Framework) are used, as these are not yet compatible with JDK9.

      FREQUENCY : always


            fmatte Fairoz Matte
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: