You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2019/10/22 14:40:00 UTC

[jira] [Commented] (GROOVY-9287) @Delegate( exclude ) option is ignored

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

Eric Milles commented on GROOVY-9287:
-------------------------------------

When delegating to a Map, you open up quite a bit of dynamic behavior.  Typically Delegate would be used on a simple type to expose the getters/setters.

> @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
>  
> {color:#000043}class {color}WMap {
>   String {color:#660e7a}name{color};
>   {color:#808000}@Delegate{color}( excludes = {color:#008000}"name,a" {color})
>   Map<String,String> {color:#660e7a}data{color};
>  
>   WMap(String name, Map<String, String> data) {
>     {color:#000043}this{color}.{color:#660e7a}name {color}= name
>     {color:#000043}this{color}.{color:#660e7a}data {color}= data
>   }
> }
> {color:#000043}def {color}{color:#008000}'Test WMap properties'{color}() {
>   given:
>    {color:#000043}def {color}map = {color:#000043}new {color}WMap({color:#008000}'example'{color},[{color:#008000}'a'{color}:{color:#008000}'valA'{color},{color:#008000}b{color}:{color:#008000}'valB'{color},{color:#008000}'name'{color}:{color:#008000}'wierd'{color}])
>   expect:
>    map.{color:#008000}name {color}== {color:#008000}'example' {color}{color:#808080}// fail it's "wierd"
> {color}   map.{color:#008000}a {color}== {color:#008000}'valA' {color}{color:#808080}// but what about exclude = a ?
> {color}}
>  
> 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)