RFR: 8332297: annotation processor that generates records sometimes fails due to NPE in javac

Jan Lahoda jlahoda at openjdk.org
Tue May 21 08:17:03 UTC 2024


On Fri, 17 May 2024 18:52:36 GMT, Vicente Romero <vromero at openjdk.org> wrote:

> This bug is a bit particular regarding how to reproduce it. Having:
> 
> import java.lang.annotation.*;
> public @interface RecordBuilder {}
> 
> interface Conf {
>     int maxConcurrency( );
> }
> 
> and:
> 
> import java.lang.annotation.*;
> public @interface RecordBuilder {
> }
> 
> and:
> 
> import java.util.*;
> import java.io.*;
> 
> import javax.annotation.processing.*;
> import javax.lang.model.element.TypeElement;
> import javax.tools.StandardLocation;
> 
> @SupportedAnnotationTypes("*")
> public class SimplestAP extends AbstractProcessor {
>     @Override
>     public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
>         if (roundEnv.processingOver()) {
>             try (Writer w = processingEnv.getFiler().createSourceFile("ConfRecord").openWriter()) {
>                 w.append("@RecordBuilder public record ConfRecord(int maxConcurrency) implements Conf {}");
>             } catch (IOException ex) {
>                 throw new IllegalStateException(ex);
>             }
>         }
>         return true;
>     }
> }
> 
> do:
> 
> javac SimplestAP.java
> 
> javac -processor SimplestAP Conf.java //compiles fine
> javac -processor SimplestAP Conf.java // fails with:
> 
> 
> warning: No SupportedSourceVersion annotation found on SimplestAP, returning RELEASE_6.
> warning: Supported source version 'RELEASE_6' from annotation processor 'SimplestAP' less than -source '23'
> warning: File for type 'ConfRecord' created in the last round will not be subject to annotation processing.
> 3 warnings
> An exception has occurred in the compiler (23-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 invoke "com.sun.tools.javac.code.Symbol$MethodSymbol.flags()" because "rc.accessor" is null
> at jdk.compiler/com.sun.tools.javac.comp.Lower.lambda$generateMandatedAccessors$6(Lower.java:2403)
> at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:196)
> at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133)
> at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1939)
> at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:570)
> at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:560)
> at java.base/java.util.s...

Looks reasonable to me.

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

Marked as reviewed by jlahoda (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/19288#pullrequestreview-2067884025


More information about the compiler-dev mailing list