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

Chen Liang liach at openjdk.org
Wed Aug 13 13:13:16 UTC 2025


On Wed, 13 Aug 2025 12:28:16 GMT, Jan Lahoda <jlahoda 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?

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

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


More information about the compiler-dev mailing list