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 2022/04/07 16:43:00 UTC

[jira] [Updated] (GROOVY-10089) SC: GroovyCastException for map value as constructor for Collection

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

Eric Milles updated GROOVY-10089:
---------------------------------
    Fix Version/s: 3.0.11

> SC: GroovyCastException for map value as constructor for Collection
> -------------------------------------------------------------------
>
>                 Key: GROOVY-10089
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10089
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static compilation
>            Reporter: Eric Milles
>            Assignee: Eric Milles
>            Priority: Major
>             Fix For: 4.0.0-beta-1, 3.0.11
>
>
> Our tree-building code is a bit more than this, but I was able to trim back and still produce the run-time exception:
> {code:groovy}
> def test(... attributes) {
>     List one = [
>         [id:'x', options:[count:1]]
>     ]
>     List two = attributes.collect {
>         def node = Collections.singletonMap('children', one)
>         if (node) {
>             node = node.get('children').find { child -> child['id'] == 'x' }
>         }
>         // inferred type of node must be something like Map<String,List<...>>
>         [id: it['id'], name: node['name'], count: node['options']['count']]
>         //                                        ^^^^^^^^^^^^^^^ GroovyCastException (map ctor for Collection)
>     }
>     two
> }
> test( [id:'x'] )
> {code}
> Changing the type of "one" from "List" to "def" stops the madness.



--
This message was sent by Atlassian Jira
(v8.20.1#820001)