You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Simon Rehm (Jira)" <ji...@apache.org> on 2020/12/22 16:24:00 UTC
[jira] [Updated] (GROOVY-9872) GroovyCastException when using a map
while iterating over something in a @CompileStatic object
[ https://issues.apache.org/jira/browse/GROOVY-9872?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Simon Rehm updated GROOVY-9872:
-------------------------------
Summary: GroovyCastException when using a map while iterating over something in a @CompileStatic object (was: GroovyCastException when using a map while iterating over something in the constructor of a @CompileStatic object)
> 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
> Priority: Major
>
> 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}
> 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.3.4#803005)