RFR: 8372336: javac fails with an exception when a class is missing while evaluating conditional expression [v2]

Vicente Romero vromero at openjdk.org
Tue Nov 25 19:27:00 UTC 2025


On Tue, 25 Nov 2025 17:37:17 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:

>> 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.

lgtm

-------------

Marked as reviewed by vromero (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/28490#pullrequestreview-3506504070


More information about the compiler-dev mailing list