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/22 19:58:00 UTC

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

Amin Ziaei created GROOVY-9009:
----------------------------------

             Summary: 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


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)