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

groovy.transform.builder.Builder does not create methods for super-class setters

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 4.0.13
    • None
    • ast builder
    • None
    • Windows 10 x64, JDK 11

    Description

      Groovy version: 4.0.13

      I have two classes.

      First base class:

      class BaseDto {
          private String phone
      
          String getPhone() {
              return phone
          }
      
          void setPhone(String phone) {
              this.phone = phone
          }
      } 

      Second class, that extends first class:

      @Builder(includeSuperProperties = true, useSetters = true, allProperties = true, allNames = true)
      class ExtendedDto extends BaseDto {
          String id
      
          String getId() {
              return id
          }
      
          void setId(String id) {
              this.id = id
          }
      } 

      I try to call builder like this:

      ExtendedDto.builder().phone('123').build()

      But exception has been thrown: 

      groovy.lang.MissingMethodException: No signature of method: ExtendedDto$ExtendedDtoBuilder.phone() is applicable for argument types: (String) values: [123]
      Possible solutions: print(java.io.PrintWriter), print(java.lang.Object), any(), find(), id(java.lang.String), any(groovy.lang.Closure)
          at org.codehaus.groovy.vmplugin.v8.IndyInterface.fromCache(IndyInterface.java:321)
          at ExtendedDto$ExtendedDtoBuilder.methodMissing(ExtendedDto.groovy)

      It seems, that method

      org.codehaus.groovy.transform.BuilderASTTransformation.AbstractBuilderStrategy#getPropertyInfoFromClassNode(org.codehaus.groovy.transform.BuilderASTTransformation, org.codehaus.groovy.ast.AnnotationNode, org.codehaus.groovy.ast.ClassNode, java.util.List<java.lang.String>, java.util.List<java.lang.String>, boolean, boolean)

      always calls method BeanUtils.getAllProperties with includeSuperProperties = false.

      Imho, getPropertyInfoFromClassNode should call BeanUtils.getAllProperties with includeSuperProperties = true, when DTO has annotation with includeSuperProperties = true.

      Attachments

        1. 2023-08-14_11-49-17.png
          62 kB
          Yuri Kudryavtsev

        Activity

          People

            Unassigned Unassigned
            kyurik Yuri Kudryavtsev
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: