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

Groovy3 CompileStatic bug: Method clone is protected in java.lang.Object

    XMLWordPrintableJSON

Details

    Description

      The following code compiles on groovy 2 but does not compile on groovy 3

      package a.b.c
      
      import groovy.transform.CompileStatic
      
      @CompileStatic
      class ABC implements DEF {
          public double[] _array
      
          ABC() { }
      
          DEF clone() {
              ABC abc = (ABC) super.clone()
              abc._array = _array.clone() as double[]
              return abc
          }
      }
      
      public interface DEF extends Cloneable {
          public DEF clone() throws CloneNotSupportedException;
      }
       

      It gives the following error message:

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      ABC.groovy: 15: Method clone is protected in java.lang.Object @ line 15, column 22.
                 abc._array = _array.clone() as double[]
                              ^
      
      1 error
      

      However if I don't put the class in a package (i.e. remove package a.b.c) it compiles fine.

      (this might relate to this issue GROOVY-9874)

      Attachments

        Issue Links

          Activity

            People

              emilles Eric Milles
              olofasbrink Olof Asbrink
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: