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 2019/02/25 06:18:00 UTC
[jira] [Resolved] (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:all-tabpanel ]
Paul King resolved GROOVY-9009.
-------------------------------
Resolution: Fixed
Assignee: Paul King
Fix Version/s: 2.5.7
3.0.0-alpha-5
Should be fixed in the next release. A possible workaround would be to remove @CompileStatic from the class and just place it on any methods.
> 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)