Skip to content

semanticdb-javac terminates in error "silently", due to a NullPointerException #686

@spangaer

Description

@spangaer

Platform: VSCode/Metals/Bloop on Windows 10 with Java 8 GraalVM 20

This issue is a propagation of scalameta/metals#6191

It looks like it went sour in:

Still broken against v0.9.9 against which I did my debugging below.

It seems to be triggered by an annotation on a local variable

  private <T> Function<InvocationHandler, T> getConstructor(Class<T> contract) {
    @SuppressWarnings("unchecked")
    Constructor<T> constructor = (Constructor<T>) 

Which throws a NullPointerException here

JavacTrees.getElement(TreePath) (c:\Program Files\Java\graalvm-ce-java8-20.3.3\src\com\sun\tools\javac\api\JavacTrees.java:319)
JavacTrees.getElement(TreePath) (c:\Program Files\Java\graalvm-ce-java8-20.3.3\src\com\sun\tools\javac\api\JavacTrees.java:119)
SemanticdbTrees.annotationBuilder(AnnotationTree) (Unknown Source:87)
SemanticdbTrees.annotations(Tree) (Unknown Source:71)
SemanticdbVisitor.emitSymbolInformation(Element,Tree) (Unknown Source:134)
SemanticdbVisitor.emitSymbolOccurrence(Element,Tree,Name,Semanticdb$SymbolOccurrence$Role,CompilerRange) (Unknown Source:114)
SemanticdbVisitor.resolveVariableTree(VariableTree,TreePath) (Unknown Source:282)
SemanticdbVisitor.resolveNodes() (Unknown Source:209)
SemanticdbVisitor.buildTextDocument(CompilationUnitTree) (Unknown Source:94)
SemanticdbTaskListener.onFinishedAnalyze(TaskEvent) (Unknown Source:96)
SemanticdbTaskListener.finished(TaskEvent) (Unknown Source:63)
ClientCodeWrapper$WrappedTaskListener.finished(TaskEvent) (c:\Program Files\Java\graalvm-ce-java8-20.3.3\src\com\sun\tools\javac\api\ClientCodeWrapper.java:681)
MultiTaskListener.finished(TaskEvent) (c:\Program Files\Java\graalvm-ce-java8-20.3.3\src\com\sun\tools\javac\api\MultiTaskListener.java:111)
JavaCompiler.flow(Env,Queue) (c:\Program Files\Java\graalvm-ce-java8-20.3.3\src\com\sun\tools\javac\main\JavaCompiler.java:1342)
JavaCompiler.flow(Env) (c:\Program Files\Java\graalvm-ce-java8-20.3.3\src\com\sun\tools\javac\main\JavaCompiler.java:1296)
JavaCompiler.compile2() (c:\Program Files\Java\graalvm-ce-java8-20.3.3\src\com\sun\tools\javac\main\JavaCompiler.java:901)
JavaCompiler.compile(List,List,Iterable) (c:\Program Files\Java\graalvm-ce-java8-20.3.3\src\com\sun\tools\javac\main\JavaCompiler.java:860)
Main.compile(String[],String[],Context,List,Iterable) (c:\Program Files\Java\graalvm-ce-java8-20.3.3\src\com\sun\tools\javac\main\Main.java:523)
Main.compile(String[],Context,List,Iterable) (c:\Program Files\Java\graalvm-ce-java8-20.3.3\src\com\sun\tools\javac\main\Main.java:381)
Main.compile(String[],Context) (c:\Program Files\Java\graalvm-ce-java8-20.3.3\src\com\sun\tools\javac\main\Main.java:370)

JavacTrees


    public Symbol getElement(TreePath path) {
        JCTree tree = (JCTree) path.getLeaf();

Because here

Element variableSym = trees.getElement(variableTreePath);

variableTreePath ends up being null.

For some reason the new construct cannot cope with annotations on local variables. If I move the annotation to the method level it seems to get past the null pointer problem.

Why it fails on that exact instance is unclear, I have different java codebases where I use it on locals, fields or classes where I didn't see the issue surface.
Perhaps it has to do with the method being private (e.g. the variable was named local14 in the tree model).

More I wasn't able to determine whilst debugging on the release version of the Javac plugin.
I think I collected al relevant info. So far I still have the break on the code line just before the NullPointerException occurs should I need to attempt to gather anything else.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions