[ 
https://issues.apache.org/jira/browse/GROOVY-12680?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Paul King resolved GROOVY-12680.
--------------------------------
    Fix Version/s: 7.0.0-alpha-1
         Assignee: Paul King
       Resolution: Fixed

This is a candidate for a partial backport to 6 and maybe we'd need to bring 
GROOVY-12675 along with it. It moves us in the right direction but it isn't 
clear whether any folks are relying on the "broken" behavior.

> A closure's metaclass reads and overwrites private fields of 
> groovy.lang.Closure
> --------------------------------------------------------------------------------
>
>                 Key: GROOVY-12680
>                 URL: https://issues.apache.org/jira/browse/GROOVY-12680
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 4.0.33, 5.0.8, 5.1.3, 6.0.0
>            Reporter: Scott Murphy Heiberg
>            Assignee: Paul King
>            Priority: Major
>             Fix For: 7.0.0-alpha-1
>
>
> {code:groovy}
> def c = { -> 1 }
> assert c.metaClass.getProperty(c, 'bcw') == null
> assert c.metaClass.getProperty(c, 'serialVersionUID') == 4368710879820278874L
> assert c.metaClass.getMetaProperty('thisType') != null
> c.metaClass.setProperty(c, 'thisType', String)   // overwrites Closure's 
> private field
> class C {
>     private secret = 'C'
>     def read() {
>         Closure c = { -> secret }
>         c.metaClass.setProperty(c, 'thisType', Object)
>         c()
>     }
> }
> class D extends C {}
> new D().read()
> {code}
> *Actual:* getProperty returns the values of the private fields bcw, 
> serialVersionUID, thisType, mopPerturbed and PROPERTY_GETTERS of Closure, 
> also under capitalised names such as ThisType. getMetaProperty and 
> hasProperty return them. setProperty overwrites thisType and mopPerturbed. 
> After thisType is overwritten, the last line fails with "No such property: 
> secret for class: D". With the TO_SELF resolve strategy, plain {{c.thisType = 
> String}} does the same.
> *Expected:* MissingPropertyException from getProperty and setProperty, and 
> null from getMetaProperty and hasProperty, as the metaclass of any other 
> subclass gives for its superclass's private fields.
> ClosureMetaClass delegates property access to a MetaClassImpl of Closure 
> itself, which indexes Closure's own private members. A generated closure 
> class does not inherit them. Related: GROOVY-12675 (the same members in 
> getProperties).
> Verified: 5.0.8, 6.0.0 and master (including the setProperty overwrite of 
> thisType); 4.0.33 read side only (bcw and serialVersionUID).



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to