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 2021/10/19 15:16:00 UTC

[jira] [Commented] (GROOVY-10319) Groovy3 CompileStatic bug: Method clone is protected in java.lang.Object

    [ https://issues.apache.org/jira/browse/GROOVY-10319?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17430602#comment-17430602 ] 

Eric Milles commented on GROOVY-10319:
--------------------------------------

According to JLS, arrays provide clone method.  https://docs.oracle.com/javase/specs/jls/se8/html/jls-10.html#jls-10.7

I've seen special handling for "length".  Looks like we need similar for "clone()".

> Groovy3 CompileStatic bug: Method clone is protected in java.lang.Object
> ------------------------------------------------------------------------
>
>                 Key: GROOVY-10319
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10319
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static compilation
>    Affects Versions: 3.0.8
>         Environment: JDK11 (11.0.12)
>            Reporter: Olof Asbrink
>            Priority: Major
>
> The following code compiles on groovy 2 but does not compile on groovy 3
> {code:java}
> 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;
> }
>  {code}
> It gives the following error message:
> {code:java}
> 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
> {code}
> 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: https://issues.apache.org/jira/browse/GROOVY-9874)



--
This message was sent by Atlassian Jira
(v8.3.4#803005)