You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Amin Ziaei (JIRA)" <ji...@apache.org> on 2019/02/27 15:09:00 UTC

[jira] [Commented] (GROOVY-9009) AutoClone throws ClassCastException when used with @ToString or @EqualsAndHashCode

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

Amin Ziaei commented on GROOVY-9009:
------------------------------------

Another workaround is using COPY_CONSTRUCTOR style on the annotation. Just leaving this here for reference.

> 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-alpha-5, 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)