[
https://issues.apache.org/jira/browse/GROOVY-12684?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Scott Murphy Heiberg updated GROOVY-12684:
------------------------------------------
Description:
Attribute access ({{.@}}) on a closure reaches the private implementation
fields of {{groovy.lang.Closure}}, although the closure is an instance of a
generated subclass and attribute access does not reach a superclass's private
fields for any other class:
{code:groovy}
def c = { -> 1 }
c.@thisType = String // overwrites Closure's private field
assert c.@thisType == String
c.@bcw // reads Closure's private BooleanClosureWrapper cache
class A { private int x = 1 }
class B extends A {}
new B().@x // MissingFieldException
{code}
{{c.@delegate}}, {{c.@owner}}, {{c.@thisObject}}, {{c.@resolveStrategy}} and
{{c.@directive}} reach private fields of {{Closure}} the same way, and existing
code relies on them (for example to read the owner without going through
{{getOwner()}}). So the choice is between leaving attribute access as it is,
and declining the fields that are implementation details ({{thisType}}, {{bcw}}
and any later caches) while keeping the ones code uses today.
GROOVY-12680 (apache/groovy#3201) stops {{ClosureMetaClass}} from exposing the
private fields of {{Closure}} as properties ({{c.thisType}}, {{c.bcw}}); it
leaves attribute access unchanged. Seen on 6.0.0 and master. In 4.0.33 the
{{thisType}} field does not exist.
was:
Attribute access ({{.@}}) on a closure reaches the private implementation
fields of {{groovy.lang.Closure}}, although the closure is an instance of a
generated subclass and attribute access does not reach a superclass's private
fields for any other class:
{code:groovy}
def c = { -> 1 }
c.@thisType = String // overwrites Closure's private field
assert c.@thisType == String
c.@bcw // reads Closure's private BooleanClosureWrapper cache
class A { private int x = 1 }
class B extends A {}
new B().@x // MissingFieldException
{code}
{{c.@delegate}}, {{c.@owner}}, {{c.@thisObject}}, {{c.@resolveStrategy}} and
{{c.@maximumNumberOfParameters}} reach private fields of {{Closure}} the same
way, and existing code relies on them (for example to read the owner without
going through {{getOwner()}}). So the choice is between leaving attribute
access as it is, and declining the fields that are implementation details
({{thisType}}, {{bcw}}, {{serialVersionUID}} and any later caches) while
keeping the ones code uses today.
GROOVY-12680 (apache/groovy#3201) stops {{ClosureMetaClass}} from exposing the
private fields of {{Closure}} as properties ({{c.thisType}}, {{c.bcw}}); it
leaves attribute access unchanged. Seen on 6.0.0 and master. In 4.0.33 the
{{thisType}} field does not exist.
> Attribute access on a closure reads and writes the private implementation
> fields of Closure
> -------------------------------------------------------------------------------------------
>
> Key: GROOVY-12684
> URL: https://issues.apache.org/jira/browse/GROOVY-12684
> Project: Groovy
> Issue Type: Improvement
> Affects Versions: 6.0.0
> Reporter: Scott Murphy Heiberg
> Priority: Major
>
> Attribute access ({{.@}}) on a closure reaches the private implementation
> fields of {{groovy.lang.Closure}}, although the closure is an instance of a
> generated subclass and attribute access does not reach a superclass's private
> fields for any other class:
> {code:groovy}
> def c = { -> 1 }
> c.@thisType = String // overwrites Closure's private field
> assert c.@thisType == String
> c.@bcw // reads Closure's private BooleanClosureWrapper
> cache
> class A { private int x = 1 }
> class B extends A {}
> new B().@x // MissingFieldException
> {code}
> {{c.@delegate}}, {{c.@owner}}, {{c.@thisObject}}, {{c.@resolveStrategy}} and
> {{c.@directive}} reach private fields of {{Closure}} the same way, and
> existing code relies on them (for example to read the owner without going
> through {{getOwner()}}). So the choice is between leaving attribute access as
> it is, and declining the fields that are implementation details
> ({{thisType}}, {{bcw}} and any later caches) while keeping the ones code uses
> today.
> GROOVY-12680 (apache/groovy#3201) stops {{ClosureMetaClass}} from exposing
> the private fields of {{Closure}} as properties ({{c.thisType}}, {{c.bcw}});
> it leaves attribute access unchanged. Seen on 6.0.0 and master. In 4.0.33 the
> {{thisType}} field does not exist.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)