[ 
https://issues.apache.org/jira/browse/GROOVY-12680?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18137542#comment-18137542
 ] 

ASF GitHub Bot commented on GROOVY-12680:
-----------------------------------------

testlens-app[bot] commented on PR #3201:
URL: https://github.com/apache/groovy/pull/3201#issuecomment-6613783854

   ## ✅ All tests passed ✅
   
   🏷️ Commit: 2acb70cf4edd276d9533c0dbd9e19e64c080173c
   ▶️ Tests:  124299 executed
   ⚪️ Checks: 27/27 completed
   
   ---
   _Learn more about TestLens at 
[testlens.app/docs](https://testlens.app/docs/features/pr-comment/)._
   




> 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, 7.0.0-alpha-1, 6.0.0
>            Reporter: Scott Murphy Heiberg
>            Priority: Major
>
> {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