Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-10089

SC: GroovyCastException for map value as constructor for Collection

    XMLWordPrintableJSON

Details

    Description

      Our tree-building code is a bit more than this, but I was able to trim back and still produce the run-time exception:

      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'] )
      

      Changing the type of "one" from "List" to "def" stops the madness.

      Attachments

        Activity

          People

            emilles Eric Milles
            emilles Eric Milles
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: