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

Problem With EqualsAndHashCode And Primitive Boolean Properties

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.1.6, 2.1.9
    • 2.2.0-rc-3
    • None
    • None

    Description

      If a class marked with @EqualsAndHashCode contains a boolean property as well as a corresponding "is*" method the EqualsAndHashCode transformation generates some invalid code.

      equals_and_hash_code $ groovy -version
      Groovy Version: 2.1.9 JVM: 1.6.0_51 Vendor: Apple Inc. OS: Mac OS X
      equals_and_hash_code $ 
      equals_and_hash_code $ cat Demo.groovy 
      @groovy.transform.EqualsAndHashCode
      class Demo {
          boolean myBooleanProperty
      
          boolean isMyBooleanProperty() {
              false
          }
      
          static main(args) {
              println new Demo().hashCode()
          }
      }
      
      equals_and_hash_code $ 
      equals_and_hash_code $ groovy Demo.groovy 
      Caught: groovy.lang.MissingMethodException: No signature of method: Demo.getMyBooleanProperty() is applicable for argument types: () values: []
      Possible solutions: setMyBooleanProperty(boolean), isMyBooleanProperty()
      groovy.lang.MissingMethodException: No signature of method: Demo.getMyBooleanProperty() is applicable for argument types: () values: []
      Possible solutions: setMyBooleanProperty(boolean), isMyBooleanProperty()
      	at Demo.hashCode(Demo.groovy)
      	at Demo$hashCode.call(Unknown Source)
      	at Demo.main(Demo.groovy:10)
      equals_and_hash_code $ 
      

      I have tested with Groovy 2.1.6 and 2.1.9 and both demonstrate this behavior.

      This problem is manifesting in Grails. See http://jira.grails.org/browse/GRAILS-10701.

      Attachments

        Activity

          People

            paulk Paul King
            brownj Jeff Brown
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: