title: Groovy + JsonSlurper strange behaviour
body: <p>I have following code to parse a JSON file:</p>
  
  <pre><code>@Override
  Map&lt;String, Configuration&gt; parseJson() {
      Object configurationFile = readConfigurationFile()
      configurationFile.schemas.each { schemaProtectionInformation -&gt;
          processing(schemaProtectionInformation)
      }
  }
  
  private Object readConfigurationFile() {
      InputStream is = getClass().getClassLoader().getResourceAsStream("test.json")
      BufferedReader reader = new BufferedReader(new InputStreamReader(is))
      return new JsonSlurper().parse(reader)
  }
  </code></pre>
  
  <p>To process following JSON file:</p>
  
  <pre><code>{
    "schemas": [
      {
        "name": "plan_pm_test",
        "protectedDimensions": [
          {
            "name": "dActivityWbs",
            "usedToSecureFactTable": true,
            "aliasInFactTable": "PLAN_WBS",
            "levels" : ["LEVEL_1_ID","LEVEL_2_ID","LEVEL_3_ID","LEVEL_4_ID","LEVEL_5_ID","LEVEL_6_ID","LEVEL_7_ID","LEVEL_8_ID","LEVEL_9_ID"]
          },
          {
            "name": "dResponsibleOrganicUnit",
            "usedToSecureFactTable": true,
            "aliasInFactTable": "RES_ORG_UNIT",
            "levels" : ["ID","LEVEL_1_ID","LEVEL_2_ID"]
          },
          {
            "name": "dContributionOrganicUnit",
            "usedToSecureFactTable": true,
            "aliasInFactTable": "CON_ORG_UNIT",
            "levels" : ["ID","LEVEL_1_ID","LEVEL_2_ID"]
          }
        ]
      }
    ]
  }
  </code></pre>
  
  <p>If I execute this code I will receive following error:</p>
  
  <pre><code>Cannot cast object '[{name=plan_pm_test, protectedDimensions=[{aliasInFactTable=PLAN_WBS, levels=[LEVEL_1_ID, LEVEL_2_ID, LEVEL_3_ID, LEVEL_4_ID, LEVEL_5_ID, LEVEL_6_ID, LEVEL_7_ID, LEVEL_8_ID, LEVEL_9_ID], name=dActivityWbs, usedToSecureFactTable=true}, {aliasInFactTable=RES_ORG_UNIT, levels=[ID, LEVEL_1_ID, LEVEL_2_ID], name=dResponsibleOrganicUnit, usedToSecureFactTable=true}, {aliasInFactTable=CON_ORG_UNIT, levels=[ID, LEVEL_1_ID, LEVEL_2_ID], name=dContributionOrganicUnit, usedToSecureFactTable=true}]}]' with class 'java.util.ArrayList' to class 'java.util.Map' due to: groovy.lang.GroovyRuntimeException: Could not find matching constructor for: java.util.Map(groovy.json.internal.LazyMap)
  org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '[{name=plan_pm_test, protectedDimensions=[{aliasInFactTable=PLAN_WBS, levels=[LEVEL_1_ID, LEVEL_2_ID, LEVEL_3_ID, LEVEL_4_ID, LEVEL_5_ID, LEVEL_6_ID, LEVEL_7_ID, LEVEL_8_ID, LEVEL_9_ID], name=dActivityWbs, usedToSecureFactTable=true}, {aliasInFactTable=RES_ORG_UNIT, levels=[ID, LEVEL_1_ID, LEVEL_2_ID], name=dResponsibleOrganicUnit, usedToSecureFactTable=true}, {aliasInFactTable=CON_ORG_UNIT, levels=[ID, LEVEL_1_ID, LEVEL_2_ID], name=dContributionOrganicUnit, usedToSecureFactTable=true}]}]' with class 'java.util.ArrayList' to class 'java.util.Map' due to: groovy.lang.GroovyRuntimeException: Could not find matching constructor for: java.util.Map(groovy.json.internal.LazyMap)
      at cern.ais.datawarehouse.baserver.mondriansecurity.common.schemaprotectionconfiguration.JsonResourceFileConfigurationRepositoryPopulator.readConfiguration(JsonResourceFileConfigurationRepositoryPopulator.groovy:23)
      at cern.ais.datawarehouse.baserver.mondriansecurity.common.schemaprotectionconfiguration.JsonResourceFileConfigurationRepositoryPopulatorTest.tes(JsonResourceFileConfigurationRepositoryPopulatorTest.groovy:12)
  </code></pre>
  
  <p>So of course I started debugging application step by step to see which part of code in part <em>processing()</em> throws this exception. Surprisingly all the code there executes normally: without throwing exception and returning results I except.</p>
  
  <p>What suprised me even more is that when I changed slightly the code of first method, it works without producing the exception.</p>
  
  <pre><code>@Override
  Map&lt;String, Configuration&gt; readConfiguration() {
      Object configurationFile = readConfigurationFile()
      configurationFile.schemas.each { schemaProtectionInformation -&gt;
          processing(schemaProtectionInformation)
      }
      println "test 2"
  }
  </code></pre>
  
  <p>I have no idea how the <em>println</em> method can change anything there. Of course it does not have to be necessarily <em>println</em> method that does the trick. So if I do something like this:</p>
  
  <pre><code>@Override
  Map&lt;String, Configuration&gt; readConfiguration() {
      Object configurationFile = readConfigurationFile()
      configurationFile.schemas.each { schemaProtectionInformation -&gt;
          processing(schemaProtectionInformation)
      }
      test()
  }
  
  void test() {
  
  }
  </code></pre>
  
  <p>It will work as well (no expcetion thrown). I have no idea why having some additional code after processing the json file should make any change here.</p>
  
  <p>Just now I have actually commented out the processing method, so that the method body looks like below.</p>
  
  <pre><code>@Override
  Map&lt;String, Configuration&gt; readConfiguration() {
      Object configurationFile = readConfigurationFile()
      configurationFile.schemas.each { schemaProtectionInformation -&gt;
          //processing(schemaProtectionInformation)
      }
  }
  </code></pre>
  
  <p>And even though I receive the same exception. Hence, the error is not related to the implementation of processing method.</p>
  
  <p>I would greatly appreciate your input.</p>