Marcin Zajaczkowski created GROOVY-10937:
--------------------------------------------

             Summary: record + lombok + groovy == Cannot specify duplicate 
annotation on the same member : lombok.NonNull
                 Key: GROOVY-10937
                 URL: https://issues.apache.org/jira/browse/GROOVY-10937
             Project: Groovy
          Issue Type: Bug
          Components: Compiler
    Affects Versions: 4.0.9
            Reporter: Marcin Zajaczkowski


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:
{code:java}
// 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 {
    }
}{code}
The error is:
{code:java}
[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
{code}
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).



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to