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

SC: GroovyCastException for map value as constructor for Collection

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 4.0.0-beta-1
    • Component/s: Static compilation
    • Labels:
      None

      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

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

              Dates

              • Created:
                Updated:
                Resolved: