You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2022/05/22 16:06:00 UTC
[jira] [Updated] (GROOVY-7016) AutoClone does not check for existing copy constructor
[ https://issues.apache.org/jira/browse/GROOVY-7016?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Eric Milles updated GROOVY-7016:
--------------------------------
Labels: ClassFormatError (was: )
> AutoClone does not check for existing copy constructor
> ------------------------------------------------------
>
> Key: GROOVY-7016
> URL: https://issues.apache.org/jira/browse/GROOVY-7016
> Project: Groovy
> Issue Type: Bug
> Components: groovy-jdk
> Affects Versions: 2.4.0-beta-2
> Reporter: Venkat Srinivasan
> Assignee: Paul King
> Priority: Minor
> Labels: ClassFormatError
> Fix For: 2.3.7, 2.4.0-beta-3
>
>
> @AutoClone with COPY_CONSTRUCTOR style does not check if a copy constructor already exists. There are times when the author may want to write their own copy constructor.
> Please see example below:
> {code}
> import groovy.transform.AutoClone
> import groovy.transform.AutoCloneStyle
> @AutoClone(style = AutoCloneStyle.COPY_CONSTRUCTOR)
> class MyClass {
> MyClass(MyClass other) {
> println 'custom copy constructor'
> }
> }
> {code}
> If we compile and examine the generated code, we see duplication:
> {noformat}
> > groovyc MyClass.groovy
> > javap -c MyClass | grep "MyClass("
> protected MyClass(MyClass);
> protected MyClass(MyClass);
> >
> {noformat}
> This leads to compilation error later when MyClass.class is used in another code, like so,
> {noformat}
> Caught: java.lang.ClassFormatError: Duplicate method name&signature in class file MyClass
> java.lang.ClassFormatError: Duplicate method name&signature in class file MyClass
> {noformat}
--
This message was sent by Atlassian Jira
(v8.20.7#820007)