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

Trees.getScope crashes for annotated local records

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 15
    • Fix Version/s: 16
    • Component/s: tools
    • Labels:
      None
    • Subcomponent:
    • Resolved In Build:
      b02

      Backports

        Description

        Consider code like this:
        ---
        class Test {
            void t() {
                record R(@Annotation int i) {}
            }
        }
        @interface Annotation {}
        ---

        Calling Trees.getScope for a TreePath pointing at @Annotation in @Annotation int i will crash with:
        ---
        java.lang.NullPointerException
        at jdk.compiler/com.sun.tools.javac.comp.Check.validateAnnotation(Check.java:2914)
        at jdk.compiler/com.sun.tools.javac.comp.Check.validateAnnotations(Check.java:2896)
        at jdk.compiler/com.sun.tools.javac.comp.Annotate.lambda$annotateLater$1(Annotate.java:279)
        at jdk.compiler/com.sun.tools.javac.comp.Annotate.flush(Annotate.java:200)
        at jdk.compiler/com.sun.tools.javac.comp.Annotate.unblockAnnotations(Annotate.java:144)
        at jdk.compiler/com.sun.tools.javac.comp.TypeEnter.complete(TypeEnter.java:217)
        at jdk.compiler/com.sun.tools.javac.code.Symbol.complete(Symbol.java:681)
        at jdk.compiler/com.sun.tools.javac.code.Symbol$ClassSymbol.complete(Symbol.java:1409)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.visitClassDef(Attr.java:957)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:790)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:665)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:739)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStats(Attr.java:757)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.visitBlock(Attr.java:1435)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1047)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:665)
        at jdk.compiler/com.sun.tools.javac.comp.DeferredAttr.attribSpeculative(DeferredAttr.java:522)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribToTree(Attr.java:421)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStatToTree(Attr.java:414)
        at jdk.compiler/com.sun.tools.javac.api.JavacTrees.attribStatToTree(JavacTrees.java:946)
        at jdk.compiler/com.sun.tools.javac.api.JavacTrees.getAttrContext(JavacTrees.java:921)
        at jdk.compiler/com.sun.tools.javac.api.JavacTrees.getScope(JavacTrees.java:794)
        at jdk.compiler/com.sun.tools.javac.api.JavacTrees.getScope(JavacTrees.java:166)
        at TestGetScopeResult$9.visitAnnotation(TestGetScopeResult.java:600)
        at TestGetScopeResult$9.visitAnnotation(TestGetScopeResult.java:597)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCAnnotation.accept(JCTree.java:2756)
        at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:82)
        at jdk.compiler/com.sun.source.util.TreeScanner.scan(TreeScanner.java:105)
        at jdk.compiler/com.sun.source.util.TreeScanner.visitModifiers(TreeScanner.java:854)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCModifiers.accept(JCTree.java:2786)
        at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:82)
        at jdk.compiler/com.sun.source.util.TreeScanner.visitVariable(TreeScanner.java:222)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCVariableDecl.accept(JCTree.java:1001)
        at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:82)
        at jdk.compiler/com.sun.source.util.TreeScanner.scan(TreeScanner.java:105)
        at jdk.compiler/com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:113)
        at jdk.compiler/com.sun.source.util.TreeScanner.visitMethod(TreeScanner.java:205)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:925)
        at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:82)
        at jdk.compiler/com.sun.source.util.TreeScanner.scan(TreeScanner.java:105)
        at jdk.compiler/com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:113)
        at jdk.compiler/com.sun.source.util.TreeScanner.visitClass(TreeScanner.java:189)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:832)
        at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:82)
        at jdk.compiler/com.sun.source.util.TreeScanner.scan(TreeScanner.java:105)
        at jdk.compiler/com.sun.source.util.TreeScanner.visitBlock(TreeScanner.java:250)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1059)
        at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:82)
        at jdk.compiler/com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:90)
        at jdk.compiler/com.sun.source.util.TreeScanner.visitMethod(TreeScanner.java:208)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:925)
        at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:82)
        at jdk.compiler/com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:90)
        at jdk.compiler/com.sun.source.util.TreeScanner.scan(TreeScanner.java:105)
        at jdk.compiler/com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:113)
        at jdk.compiler/com.sun.source.util.TreeScanner.visitClass(TreeScanner.java:189)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:832)
        at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:82)
        at jdk.compiler/com.sun.source.util.TreeScanner.scan(TreeScanner.java:105)
        at jdk.compiler/com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:113)
        at jdk.compiler/com.sun.source.util.TreeScanner.visitCompilationUnit(TreeScanner.java:144)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCCompilationUnit.accept(JCTree.java:603)
        at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:82)
        at TestGetScopeResult.testLocalRecordAnnotation(TestGetScopeResult.java:604)
        at TestGetScopeResult.main(TestGetScopeResult.java:84)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:564)
        at java.base/java.lang.Thread.run(Thread.java:832)
        ---

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  jlahoda Jan Lahoda
                  Reporter:
                  jlahoda Jan Lahoda
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  2 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: