RFR: 8365314: javac fails with an exception for erroneous source

Jan Lahoda jlahoda at openjdk.org
Wed Aug 13 15:21:12 UTC 2025


On Wed, 13 Aug 2025 13:10:38 GMT, Chen Liang <liach at openjdk.org> wrote:

>> For very broken code like:
>> 
>> $ cat /tmp/BrokenSuppressWarnings.java
>> @SuppressWarnings
>> public class BrokenSuppressWarnings {}
>> 
>> 
>> javac may fail with an exception:
>> 
>> $ javac -XDdev /tmp/BrokenSuppressWarnings.java
>> /tmp/BrokenSuppressWarnings.java:1: error: annotation @SuppressWarnings is missing a default value for the element 'value'
>> @SuppressWarnings
>> ^
>> 1 error
>> An exception has occurred in the compiler (26-internal). Please file a bug against the Java compiler via the Java bug reporting page (https://bugreport.java.com/) after checking the Bug Database (https://bugs.java.com/) for duplicates. Include your program, the following diagnostic, and the parameters passed to the Java compiler in your report. Thank you.
>> java.lang.NullPointerException: Cannot read field "values" because "values" is null
>>         at jdk.compiler/com.sun.tools.javac.code.Lint.suppressionsFrom(Lint.java:532)
>> ...
>> printing javac parameters to: /tmp/javac.20250812_114830.args
>> 
>> 
>> This is because the `Attribute` for `value` is missing. The proposed solution here is to ignore the missing attribute/`null`, by using `instanceof`.
>
> src/jdk.compiler/share/classes/com/sun/tools/javac/code/Lint.java line 534:
> 
>> 532:             for (Attribute value : values.values) {
>> 533:                 Optional.of(value)
>> 534:                   .filter(val -> val instanceof Attribute.Constant)
> 
> Should we filter the .value field in this Attribute.Constant is indeed a String too?

There's a fairly comprehensive test checking the behavior for non-String constants:
https://github.com/openjdk/jdk/blob/001aaa1e49f2692061cad44d68c9e81a27ea3b98/test/langtools/tools/javac/recovery/AnnotationRecovery.java#L167

I am not generally opposed to adding the check, but if I would be adding a check without a test, I think we need an extraordinary good reason to add it. So, do you have an example where the check is needed?

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

PR Review Comment: https://git.openjdk.org/jdk/pull/26758#discussion_r2273800302


More information about the compiler-dev mailing list