Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
spangaer opened this issue Mar 26, 2024 · 3 comments

Comments

@spangaer
Copy link

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.

@spangaer
Copy link
Author

@Arthurm1
Copy link
Contributor

Arthurm1 commented Apr 5, 2024

@spangaer does changing the annotation to include the parameter name fix this issue?
e.g. @SuppressWarnings(value = "unchecked")

@spangaer
Copy link
Author

spangaer commented Apr 6, 2024

Yes:

  1. Putting it on the method level w.o. the a named param works:
    spangaer/semanticdb-nullpointer@0278db4
  2. Putting a named param works too it seems:
    spangaer/semanticdb-nullpointer@ce068b0

@linear linear bot closed this as not planned Won't fix, can't repro, duplicate, stale Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants