[
https://issues.apache.org/jira/browse/GROOVY-7701?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15054496#comment-15054496
]
John Wagenleitner commented on GROOVY-7701:
-------------------------------------------
A workaround would be to use
{code}
subClass.with {
delegate.type = ['String']
}
{code}
It only seems to be a problem if the name is the same but the types are
incompatible. If TopClass.type type is String it works correctly (only the
SubClass.type is set).
> 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)