Integrated: 8365689: Elements.getFileObjectOf fails with a NullPointerException when an erroneous Element is passed in
Jan Lahoda
jlahoda at openjdk.org
Mon Sep 8 12:30:17 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.
This pull request has now been integrated.
Changeset: 03c54d42
Author: Jan Lahoda <jlahoda at openjdk.org>
URL: https://git.openjdk.org/jdk/commit/03c54d4288dfd70190c3f306a44a8424f268f787
Stats: 159 lines in 2 files changed: 156 ins; 0 del; 3 mod
8365689: Elements.getFileObjectOf fails with a NullPointerException when an erroneous Element is passed in
Reviewed-by: darcy, vromero
-------------
PR: https://git.openjdk.org/jdk/pull/26836
More information about the compiler-dev
mailing list