record-builder: Cannot invoke "javax.lang.model.element.ExecutableElement.getAnnotationMirrors()" because the return value of "javax.lang.model.element.RecordComponentElement.getAccessor()" is null
We use record-builder on a project and we often get compilation errors with the following message:
Cannot invoke "javax.lang.model.element.ExecutableElement.getAnnotationMirrors()" because the return value of "javax.lang.model.element.RecordComponentElement.getAccessor()" is null
The errors happen either in Intellij IDEA or via the CLI with Maven. Running a re-build in Intellij or running the command again fixes the issue (usually a mvn verify).
I suspect it could come from the two tools using a different JDK or compilation options and each generating slightly different bytecode. However I’ve made sure that the same JDK (17.0.6) is used in both cases.
I’ve managed to capture a stack trace below. I’m not confident about being able to provide a reproducer project but if the error message is not helpful in understanding the problem I can give it a shot.
Caused by: java.lang.NullPointerException: Cannot invoke "javax.lang.model.element.ExecutableElement.getAnnotationMirrors()" because the return value of "javax.lang.model.element.RecordComponentElement.getAccessor()" is null
at io.soabase.recordbuilder.processor.InternalRecordBuilderProcessor.lambda$buildRecordComponents$2 (InternalRecordBuilderProcessor.java:143)
at java.util.stream.ReferencePipeline$3$1.accept (ReferencePipeline.java:197)
at java.util.Iterator.forEachRemaining (Iterator.java:133)
at java.util.Spliterators$IteratorSpliterator.forEachRemaining (Spliterators.java:1845)
at java.util.stream.AbstractPipeline.copyInto (AbstractPipeline.java:509)
at java.util.stream.AbstractPipeline.wrapAndCopyInto (AbstractPipeline.java:499)
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential (ReduceOps.java:921)
at java.util.stream.AbstractPipeline.evaluate (AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.collect (ReferencePipeline.java:682)
at io.soabase.recordbuilder.processor.InternalRecordBuilderProcessor.buildRecordComponents (InternalRecordBuilderProcessor.java:143)
at io.soabase.recordbuilder.processor.InternalRecordBuilderProcessor.<init> (InternalRecordBuilderProcessor.java:66)
at io.soabase.recordbuilder.processor.RecordBuilderProcessor.processRecordBuilder (RecordBuilderProcessor.java:168)
at io.soabase.recordbuilder.processor.RecordBuilderProcessor.process (RecordBuilderProcessor.java:76)
at io.soabase.recordbuilder.processor.RecordBuilderProcessor.lambda$process$0 (RecordBuilderProcessor.java:54)
at java.lang.Iterable.forEach (Iterable.java:75)
at io.soabase.recordbuilder.processor.RecordBuilderProcessor.lambda$process$1 (RecordBuilderProcessor.java:54)
at java.lang.Iterable.forEach (Iterable.java:75)
at io.soabase.recordbuilder.processor.RecordBuilderProcessor.process (RecordBuilderProcessor.java:54)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor (JavacProcessingEnvironment.java:1023)
....
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 36 (24 by maintainers)
Commits related to this issue
- In some JDKs the accessors list can be null Possible fix for #139 — committed to Randgalt/record-builder by Randgalt 4 years ago
- Delete any pre-existing classfile for RecordInterface Fixes #139 It seems the existence of an old .class file for the record being generated by `@RecordInterface` is exposing a bug in javac. This ch... — committed to Randgalt/record-builder by Randgalt 4 years ago
- For some reason. RecordComponentElement.getAccessor() is sometimes null - so, find the method manually Fixes #139 — committed to Randgalt/record-builder by Randgalt 3 years ago
- Delete existing class files to avoid JDK/IntelliJ bugs https://github.com/Randgalt/record-builder/pull/147 attempted to do this but it only did it for Record Interface classes. This commit does it fo... — committed to Randgalt/record-builder by Randgalt 3 years ago
- Delete existing class files to avoid JDK/IntelliJ bugs https://github.com/Randgalt/record-builder/pull/147 attempted to do this but it only did it for Record Interface classes. This commit does it fo... — committed to Randgalt/record-builder by Randgalt 3 years ago
- Delete existing class files to avoid JDK/IntelliJ bugs https://github.com/Randgalt/record-builder/pull/147 attempted to do this but it only did it for Record Interface classes. This commit does it fo... — committed to Randgalt/record-builder by Randgalt 3 years ago
- Delete existing class files to avoid JDK/IntelliJ bugs https://github.com/Randgalt/record-builder/pull/147 attempted to do this but it only did it for Record Interface classes. This commit does it fo... — committed to Randgalt/record-builder by Randgalt 3 years ago
- In some JDKs the accessors list can be null Possible fix for #139 — committed to Randgalt/record-builder by Randgalt 2 years ago
- In some JDKs the accessors list can be null Possible fix for #139 — committed to Randgalt/record-builder by Randgalt 2 years ago
@Randgalt we can close this issue.
Thanks @Randgalt! We haven’t moved away but stopped using RecordInterface until it gets resolved. I will try the fix one of those days.
I realize you’ve probably moved away from RecordBuilder at this point, but I may have a fix for this issue: https://github.com/Randgalt/record-builder/pull/172
Workaround for Intellj Idea (2022.3):
On Run/Debug configuration, click “Edit Configuration…” -> Modify options -> Do not build before run
Remember to compile project before running test