Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-10937

record + lombok + groovy == Cannot specify duplicate annotation on the same member : lombok.NonNull

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 4.0.9
    • 4.0.10
    • Compiler

    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:

      1. Compilation error occurs in a Groovy class not related to the problematic Java record.
      2. Groovy class must have (non related) inner interface or class.
      3. Record has must have two (or more) fields with @NotNull annotation from Lombok.
      4. 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).

      Attachments

        Activity

          People

            emilles Eric Milles
            szpak Marcin Zajaczkowski
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: