Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
4.0.9
Description
I've bumped into a strange looking compilation error in a project using JDK 17 record, Lombok's @NotNull and Groovy for tests. It took me a while to find a construction which causes that, as:
- Compilation error occurs in a Groovy class not related to the problematic Java record.
- Groovy class must have (non related) inner interface or class.
- Record has must have two (or more) fields with @NotNull annotation from Lombok.
- Some (other) Groovy class has to refer to that record.
For example:
// Java public record SampleRecordWithNonNullFromLombok( @NonNull String nonNullField, @NonNull //Two or more @NulNull annotated fields are required to trigger the problem String nonNullField2 ) {} //Groovy class ClassWithReferenceToRecord { private SampleRecordWithNonNullFromLombok sampleRecord } class ReproducerClass { //it fails to compile interface RequiredToReproduceProblem { } }
The error is:
[ERROR] Failed to execute goal org.codehaus.gmavenplus:gmavenplus-plugin:1.13.1:compileTests (default) on project record-lombok-groovy: Error occurred while calling a method on a Groovy class from classpath.: InvocationTargetException: startup failed: [ERROR] .../ReproducerClass.groovy: -1: Cannot specify duplicate annotation on the same member : lombok.NonNull [ERROR] @ line -1, column -1. [ERROR] 1 error
I created a shrank version of a reproducer:
https://github.com/szpak/code-examples-and-poc/tree/master/record-lombok-groovy
It might be a problem with the way how Lombok generates .class for Java record, however, I start here as Groovy compilation is the final reason.
I have observed that error occasionally with Groovy 3(.0.14), but it occurs every time with 4(0.9).