[prev in list] [next in list] [prev in thread] [next in thread]
List: openjdk-compiler-dev
Subject: Re: [jdk20] RFR: 8298727: Trees.getPath may crash for unnamed package
From: Jan Lahoda <jlahoda () openjdk ! org>
Date: 2022-12-15 11:37:13
Message-ID: Lr-v0DqKoEEgKoXcJPupfaOII69fjlAwP0RzUwWWOHI=.8f9f5a22-176a-47eb-8e78-dcf7b2fbecfe () github ! com
[Download RAW message or body]
On Wed, 14 Dec 2022 11:08:16 GMT, Jan Lahoda <jlahoda@openjdk.org> wrote:
> Considering an empty `package-info.java` file is normally accepted by javac (as a \
> `package-info` for the unnamed module). But, if `Trees.getPath` is used on the \
> unnamed package, a NPE occurs:
> java.lang.NullPointerException: Cannot invoke \
> "com.sun.tools.javac.tree.JCTree.accept(com.sun.tools.javac.tree.JCTree$Visitor)" \
> because "tree" is null at \
> jdk.compiler/com.sun.tools.javac.tree.TreeInfo.declarationFor(TreeInfo.java:811) at \
> jdk.compiler/com.sun.tools.javac.model.JavacElements.getTreeAndTopLevel(JavacElements.java:779)
> at jdk.compiler/com.sun.tools.javac.model.JavacElements.getTreeAndTopLevel(JavacElements.java:799)
> at jdk.compiler/com.sun.tools.javac.api.JavacTrees.getPath(JavacTrees.java:331)
> at jdk.compiler/com.sun.tools.javac.api.JavacTrees.getPath(JavacTrees.java:321)
>
>
> The reason is that `Env.tree` is initialized to the package clause in \
> `Enter.visitTopLevel`, but when the package clause is missing, `Env.tree` is \
> `null`, leading to the error above.
> The proposed fix is to set `Env.tree` to the top-level tree in this case, to keep \
> it non-null. As the empty `package-info` can be compiled, it seems reasonable for \
> the model to work on is as well, so a non-null tree needs to be set, and there's no \
> other tree that could be used, I believe.
Thanks for the review, Vicente!
-------------
PR: https://git.openjdk.org/jdk20/pull/31
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic