Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
2.4.0-beta-2
Description
@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:
import groovy.transform.AutoClone import groovy.transform.AutoCloneStyle @AutoClone(style = AutoCloneStyle.COPY_CONSTRUCTOR) class MyClass { MyClass(MyClass other) { println 'custom copy constructor' } }
If we compile and examine the generated code, we see duplication:
> groovyc MyClass.groovy > javap -c MyClass | grep "MyClass(" protected MyClass(MyClass); protected MyClass(MyClass); >
This leads to compilation error later when MyClass.class is used in another code, like so,
Caught: java.lang.ClassFormatError: Duplicate method name&signature in class file MyClass java.lang.ClassFormatError: Duplicate method name&signature in class file MyClass