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

Paul King closed GROOVY-9009.
-----------------------------

> AutoClone throws ClassCastException when used with @ToString or 
> @EqualsAndHashCode
> ----------------------------------------------------------------------------------
>
>                 Key: GROOVY-9009
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9009
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 2.5.5
>            Reporter: Amin Ziaei
>            Assignee: Paul King
>            Priority: Critical
>             Fix For: 3.0.0-beta-1, 2.5.7
>
>          Time Spent: 20m
>  Remaining Estimate: 0h
>
> Let’s say I have the following class:
> {code:java}
> @ToString(includes = 'someId')
> @CompileStatic
> @AutoClone
> class SomeClass {
>   String someId
> }
> {code}
> When I call clone, I get the following exception:
> {code:java}
> org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast 
> object 'com.some.package.SomeClass(null)' with class 
> 'com.some.package.SomeClass' to class 'java.lang.StringBuilder'
> {code}
> When I look at the decompiled .class file in Intellij, I see the following 
> clone method has been generated:
> {code:java}
> @Generated
> public SomeClass clone() throws CloneNotSupportedException {
>   StringBuilder _result = 
> (StringBuilder)ScriptBytecodeAdapter.castToType((SomeClass)ScriptBytecodeAdapter.castToType(super.clone(),
>  SomeClass.class), StringBuilder.class);
>   return (SomeClass)ScriptBytecodeAdapter.castToType(_result, 
> SomeClass.class);
> }
> {code}
> The issue is not reproducible if I remove the @ToString on the class.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to