[
https://issues.apache.org/jira/browse/GROOVY-9872?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Paul King closed GROOVY-9872.
-----------------------------
> GroovyCastException when using a map while iterating over something in a
> @CompileStatic object
> ----------------------------------------------------------------------------------------------
>
> Key: GROOVY-9872
> URL: https://issues.apache.org/jira/browse/GROOVY-9872
> Project: Groovy
> Issue Type: Bug
> Components: groovy-jdk
> Affects Versions: 2.5.14
> Reporter: Simon Rehm
> Assignee: Eric Milles
> Priority: Major
> Fix For: 2.5.15
>
>
> This odd code works fine in 2.5.13, but explodes in 2.5.14.
> My workaround for now is to remove @CompileStatic in production.
> Minimal example (spock test):
> {code:java}
> import groovy.transform.CompileStatic
> import spock.lang.Specification
> class FooTest extends Specification {
> def "test"() {
> when:
> new Foo()
> then:
> noExceptionThrown()
> }
> }
> @CompileStatic
> class Foo {
> private Map<String, String> cache = [:]
> Foo() {
> [''].each {
> cache[''] = ''
> }
> }
> }{code}
> Minimal example without Spock, while settings stuff in a map in an
> .each-iteration outside of Constructor:
> {code:java}
> new Foo().init()
> @CompileStatic
> class Foo {
> private Map<String, String> cache = [:]
> Foo() {
> }
> void init() {
> [''].each {
> cache[it] = it
> }
> }
> }
> {code}
>
>
> Full Error:
> {code:java}
> Expected no exception to be thrown, but got
> 'org.codehaus.groovy.runtime.typehandling.GroovyCastException' at
> spock.lang.Specification.noExceptionThrown(Specification.java:118)
> at FooTest.test(FooTest.groovy:10)
> Caused by: org.codehaus.groovy.runtime.typehandling.GroovyCastException:
> Cannot cast object 'Foo$_closure1@3fa2213' with class 'Foo$_closure1' to
> class 'Foo'
> at Foo$_closure1.doCall(FooTest.groovy:19)
> at Foo.<init>(FooTest.groovy:18)
> at FooTest.test(FooTest.groovy:7)
> {code}
>
--
This message was sent by Atlassian Jira
(v8.20.1#820001)