RFR: 8372336: javac fails with an exception when a class is missing while evaluating conditional expression [v2]
Jan Lahoda
jlahoda at openjdk.org
Tue Nov 25 17:37:17 UTC 2025
> Consider library code like:
>
> package test;
> public class Intermediate extends Base {}
> package test;
> public class Base {}
>
>
> this is compiled, but the `Base` is missing/deleted. Now consider use of this library:
>
> package test;
> public class Test {
> private void test(Intermediate i) {
> int j = i != null ? i.get() : -1;
> }
> }
>
>
> This fails with:
>
> java.lang.NullPointerException: Cannot invoke "com.sun.tools.javac.code.Symbol.flags()" because "sym" is null
> at jdk.compiler/com.sun.tools.javac.code.Types.memberType(Types.java:2304)
> at jdk.compiler/com.sun.tools.javac.comp.Attr.isBooleanOrNumeric(Attr.java:2143)
> at jdk.compiler/com.sun.tools.javac.comp.Attr.isBooleanOrNumeric(Attr.java:2132)
> at jdk.compiler/com.sun.tools.javac.comp.Attr.visitConditional(Attr.java:2070)
> at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCConditional.accept(JCTree.java:1580)
> at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:677)
> ...
>
>
> When attributing `i.get()`, there's a `CompletionFailure` thrown, for the missing `Base`. That is OK, but in this case, the `CompletionFailure` is caught by `Attr.attribTree`, but the problem is that the AST for the method invocation does not have the `Symbol`s filled in. But `isBooleanOrNumeric` relies on a non-`null` `Symbol`:
> https://github.com/openjdk/jdk/blob/49176e322bbb9ed1ef2f534b949b937770b54162/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java#L2147
>
> It would be possible to add a `null` check into `isBooleanOrNumeric`, but it seems more reliable to catch the `CompletionFailure` a bit sooner, and fill in the `Symbol` for the invocation. This is closer to what is being done in other similar cases.
Jan Lahoda has updated the pull request incrementally with one additional commit since the last revision:
Improving test as suggested.
-------------
Changes:
- all: https://git.openjdk.org/jdk/pull/28490/files
- new: https://git.openjdk.org/jdk/pull/28490/files/4218d5f5..83d7b253
Webrevs:
- full: https://webrevs.openjdk.org/?repo=jdk&pr=28490&range=01
- incr: https://webrevs.openjdk.org/?repo=jdk&pr=28490&range=00-01
Stats: 5 lines in 1 file changed: 4 ins; 0 del; 1 mod
Patch: https://git.openjdk.org/jdk/pull/28490.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/28490/head:pull/28490
PR: https://git.openjdk.org/jdk/pull/28490
More information about the compiler-dev
mailing list