You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (Jira)" <ji...@apache.org> on 2020/07/23 14:17:05 UTC

[jira] [Closed] (GROOVY-7701) org.codehaus.groovy.runtime.typehandling.GroovyCastException in Groovy ".with { ... }" - Block

     [ https://issues.apache.org/jira/browse/GROOVY-7701?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Paul King closed GROOVY-7701.
-----------------------------

> org.codehaus.groovy.runtime.typehandling.GroovyCastException in Groovy ".with { ... }" - Block
> ----------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-7701
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7701
>             Project: Groovy
>          Issue Type: Bug
>          Components: groovy-jdk
>    Affects Versions: 2.4.3, 2.4.4, 2.4.5
>         Environment: all?
> Tested with Ubuntu 14.04.3 LTS (64 Bit) | MacOS 10.11 and Groovy 2.4.5, 2.3.4
>            Reporter: Maik Igloffstein
>            Assignee: Eric Milles
>            Priority: Major
>             Fix For: 4.0.0-alpha-1, 3.0.5, 2.5.13
>
>          Time Spent: 0.5h
>  Remaining Estimate: 0h
>
> h1. Problem
> {code}
> subClass.with {
>   type = ['String']
> }
> {code}
> Should change _SubClass.type_ and not _TopClass.type_.
> The script works fine with _type2_ instead of _type_. Is _type_ a reserved word? I can't find any documentation about this.
> h2. Unit-Test / Groovy Console-Test
> {code}
> class SubClass{
>     List type
> }
> class TopClass{
>     int type = 10
>     @Lazy
>     List something = {
>         List tmp = []
>         for(int i = 0; i < 5; i++){
>             def subClass = new SubClass()
>             subClass.with {
>                 type = ['String'] // throws org.codehaus.groovy.runtime.typehandling.GroovyCastException
>             }
>             tmp.add(subClass)
>         }
>         tmp
>     }()
> }
> def topClass = new TopClass()
> println GroovySystem.version
> println(topClass.type)
> println(topClass.something)
> println(topClass.type)
> {code}
> h2. Exception
> {code}
> org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '[String]' with class 'java.util.ArrayList' to class 'int'
> 	at TopClass$_getSomething_closure1$_closure2.doCall(ConsoleScript3:15)
> 	at TopClass$_getSomething_closure1.doCall(ConsoleScript3:14)
> 	at TopClass$_getSomething_closure1.doCall(ConsoleScript3)
> 	at TopClass.getSomething(ConsoleScript3:11)
> 	at ConsoleScript3.run(ConsoleScript3:26)
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)