[ 
https://issues.apache.org/jira/browse/GROOVY-7701?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15045504#comment-15045504
 ] 

Shil Sinha commented on GROOVY-7701:
------------------------------------

This occurs for me with any choice of name in place of 'type'. Also, 'type' is 
not a reserved word.

> 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
>
> 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
(v6.3.4#6332)

Reply via email to