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

@TupleConstructor ignoring inherited standard Java Beans properties

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.4.13
    • 2.5.0-beta-3
    • ast builder
    • None

    Description

      Consider this (it can be pasted on the Groovy console):

      import groovy.transform.TupleConstructor
      
      public class Foobar {
        private Long id;
        
        public Long getId() { return this.id; }
        public void setId(Long id) { this.id = id; }
      }
      
      @TupleConstructor(includeSuperProperties=true)
      class Ext extends Foobar {
        String foo
      }
      
      Ext.constructors.each {
          println it
      }
      println 'end'
      

       
      The result is just:

      public Ext(java.lang.String)
      public Ext()
      end
      

      But id is a property (as per the Java Bean conventions) and I would expect it to be present in the generated constructors for Ext.

      If I replace includeSuperProperties=true with includeSuperFields=true, I get the expected result:

      public Ext()
      public Ext(java.lang.Long)
      public Ext(java.lang.Long,java.lang.String)
      end
      

      But in more complex cases, includeSuperFields=true will include unwanted fields that are not actually properties.

      Discussing this on the users mailing list with Paul King, here is his feedback:

      I think @Builder and @ToString originally had similar issues and we added an `allProperties` attribute with default true. Perhaps that is needed here too

      Attachments

        Activity

          People

            paulk Paul King
            mauromol Mauro Molinari
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: