Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-7016

AutoClone does not check for existing copy constructor

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.4.0-beta-2
    • Fix Version/s: 2.3.7, 2.4.0-beta-3
    • Component/s: groovy-jdk
    • Labels:
      None

      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
      

        Attachments

          Activity

            People

            • Assignee:
              paulk Paul King
              Reporter:
              venkats Venkat Srinivasan
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: