RFR: 8365689: Elements.getFileObjectOf fails with a NullPointerException when an erroneous Element is passed in
Vicente Romero
vromero at openjdk.org
Fri Sep 5 02:14:19 UTC 2025
On Tue, 19 Aug 2025 07:35:05 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:
> If an erroneous/unresolvable `Element` is passed to `Elements.getFileObjectOf`, it fails with an NPE like:
>
> Caused by: java.lang.NullPointerException: Cannot read field "classfile" because the return value of "com.sun.tools.javac.code.Symbol.enclClass()" is null
> at jdk.compiler/com.sun.tools.javac.model.JavacElements.getFileObjectOf(JavacElements.java:803)
> at TestFileObjectOf$PrintFiles.handleDeclaration(TestFileObjectOf.java:329)
> at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCIdent.accept(JCTree.java:2718)
>
>
> The reason is the `Symbol.enclClass()` will return `null` for the erroneous `Element`. The proposed solution herein is to return `null` for erroneous/unresolvable `Element`s.
lgtm
-------------
Marked as reviewed by vromero (Reviewer).
PR Review: https://git.openjdk.org/jdk/pull/26836#pullrequestreview-3187794108
More information about the compiler-dev
mailing list