Jochen Eddelbuettel created GROOVY-10007:
--------------------------------------------

             Summary: Breaking change in property resolution 2.4 -> 3.0
                 Key: GROOVY-10007
                 URL: https://issues.apache.org/jira/browse/GROOVY-10007
             Project: Groovy
          Issue Type: Bug
          Components: Compiler
    Affects Versions: 3.0.7, 3.0.5
         Environment: OpenJDK 11, IdeaC 2020.3.3
            Reporter: Jochen Eddelbuettel


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:
{code:java}
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"
{code}
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().



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to