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

Boolean isProperty() method does not create synthetic Boolean property

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Duplicate
    • 4.0.9, 4.0.10, 4.0.11
    • None
    • Compiler
    • None

    Description

      A class that defines a Boolean (object, not primitive) method isMyProperty() does not have the corresponding synthetic Boolean property.

      The main method of this class:

      class SyntheticBooleanProperty {
          Boolean isMyProperty() {
             return null
          }
      
          static void main(args) {
             assert (new SyntheticBooleanProperty()).myProperty == null
          }
      } 

      Fails with a MissingPropertyException:

      Exception in thread "main" groovy.lang.MissingPropertyException: No such property: myProperty for class: SyntheticBooleanProperty
          at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:67)
          at org.codehaus.groovy.vmplugin.v8.IndyGuardsFiltersAndSignatures.unwrap(IndyGuardsFiltersAndSignatures.java:161)
          at org.codehaus.groovy.vmplugin.v8.IndyInterface.fromCache(IndyInterface.java:321)
          at SyntheticBooleanProperty.main(SyntheticBooleanProperty.groovy:7) 

      This does not happen if the method's return type is (primitive) boolean.  It can be worked around by adding a Boolean getMyProperty() method.

      This happens with and without CompileStatic, and goes back at least as far as version 4.0.9.

      Here is a live demo.

      Attachments

        Activity

          People

            Unassigned Unassigned
            jasongarrett Jason Garrett
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: