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

Breaking change in property resolution 2.4 -> 3.0

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 3.0.5, 3.0.7
    • None
    • Compiler
    • OpenJDK 11, IdeaC 2020.3.3

    Description

      I've created a library utilizing propertyMissing. By convention, it expects property names to be running against camel casing conventions (starting with a single upper case letter), to avoid conflicts with actual properties (bean style, with getters).

      In Groovy 2.4 a call of obj.Owner would not be resolved to obj.getOwner(). Only obj.owner would be equivalent to obj.getOwner(). In Groovy 3.0 obj.Owner results in a call to obj.getOwner() as well. As a result, no call to propertyMissing for "Owner" occurs any more. Thus properties that used to be resolved by metaprogramming, can now result in actual method calls, which can potentially have a huge impact on the behavior of existing code.

      I've looked back into the 3.0.0 release notes and there is no mention of this being a breaking change.

      This script, who assertions were jolly fine in 2.4.15, should behave the same in 3.0.x:

      import groovy.json.JsonSlurper
      JsonSlurper.metaClass.propertyMissing = { String name -> name }
      def slurp = new JsonSlurper()
      slurp.maxSizeForInMemory = 500000
      assert slurp.maxSizeForInMemory == 500000
      assert slurp.MaxSizeForInMemory == "MaxSizeForInMemory"
      

      Interestingly, this is not a problem for setters, which suggests to me that the change is unintended behaviour get getters and should be fixed. It is a problem with @CompileStatic too. obj.Owner statically compiles to obj.getOwner().

      Attachments

        Activity

          People

            Unassigned Unassigned
            eddelplus Jochen Eddelbuettel
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: