[
https://issues.apache.org/jira/browse/GROOVY-9287?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16957589#comment-16957589
]
Paul King commented on GROOVY-9287:
-----------------------------------
There are no properties or methods declared in the {{Map}} class with name
'name' or 'a' so @Delegate just ignores your {{excludes}}. For most AST
transforms we now call {{checkPropertyList}} which would give a compile error
so you'd know that they were being ignored in those cases but we don't have
that for {{@Delegate}} yet. The constructed Groovy class is still eligible for
being treated like a map and so property-like access to the map values is still
available. In your case, you can use {{getName()}} to step around Groovy's
property-like access feature if you wish:
{code}
assert map.a == 'valA'
assert map.name == 'weird'
assert map.getName() == 'example'
{code}
> @Delegate( exclude ) option is ignored
> --------------------------------------
>
> Key: GROOVY-9287
> URL: https://issues.apache.org/jira/browse/GROOVY-9287
> Project: Groovy
> Issue Type: Bug
> Components: groovy-runtime
> Affects Versions: 2.5.4
> Environment: gradle plugin project, built with gradle 5.6.2, test
> source using spock-1.3 with
> groovy-2.5.4
> Reporter: Dariusz Hudziak
> Priority: Major
>
> It seems to me that @Delegate annotation is broken with regard to it's
> exclude property:
> Consider the following spock test:
> {code}
> class WMap {
> String name;
> @Delegate( excludes = "name,a" )
> Map<String,String> data;
>
> WMap(String name, Map<String, String> data) {
> this.name = name
> this.data = data
> }
> }
> def 'Test WMap properties'() {
> given:
> def map = new WMap('example',['a':'valA',b:'valB','name':'wierd'])
> expect:
> map.name == 'example' // fail it's "wierd" map.a == 'valA' // but what
> about exclude = a ?
> }
> {code}
> In the above example we see a class that is composed with map object.
> Despite having
> regurral name property, lookups for this property end up in the target map.
> It is stated in documentation that only functions existing on delegate target
> java type are delegated ( not any GroovyObject functions ) but it seems that
> the dynamic property for each key functionallity works on the WMap where it
> should not.
> The fact that it works is no big deal, but only if the exclude works - but
> as we can see the
> exclude is ignored and more over properties are covered which should be
> avoided
--
This message was sent by Atlassian Jira
(v8.3.4#803005)