RFR: 8372336: javac fails with an exception when a class is missing while evaluating conditional expression
Jan Lahoda
jlahoda at openjdk.org
Tue Nov 25 12:29:02 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.
-------------
Commit messages:
- 8372336: javac fails with an exception when a class is missing while evaluating conditional expression
Changes: https://git.openjdk.org/jdk/pull/28490/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=28490&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8372336
Stats: 104 lines in 2 files changed: 102 ins; 0 del; 2 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