You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Lóránt Pintér (JIRA)" <ji...@apache.org> on 2018/08/06 12:27:00 UTC

[jira] [Updated] (GROOVY-8732) @CompileStatic accesses private field in parent class

     [ https://issues.apache.org/jira/browse/GROOVY-8732?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Lóránt Pintér updated GROOVY-8732:
----------------------------------
    Summary: @CompileStatic accesses private field in parent class  (was: @CompileStatic allows access to private field in parent class)

> @CompileStatic accesses private field in parent class
> -----------------------------------------------------
>
>                 Key: GROOVY-8732
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8732
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static compilation
>    Affects Versions: 2.4.15, 2.6.0-alpha-4, 3.0.0-alpha-3, 2.5.1
>            Reporter: Lóránt Pintér
>            Priority: Major
>
> {code}
> import groovy.transform.CompileStatic
> @CompileStatic
> interface Thing {
>     void call()
> }
> @CompileStatic
> class ThingImpl implements Thing {
>     void call() {}
> }
> @CompileStatic
> class Parent {
>     private final ThingImpl thing
>     public Thing getThing() { null }
> }
> @CompileStatic
> class Child extends Parent {
>     public void doSomething() {
>         thing.call()
>     }
> }
> {code}
> Compile via: {{groovyc Example.groovy}}.
> The line {{thing.call}} in {{Child.doSomething()}} calls {{getThing()}}, but then ends up referring to the returned value according to the private field's type from {{Parent}} ({{ThingImpl}}) instead of the actual returned type ({{Thing}}). The private field from {{Parent}} (or its type) should not be visible to {{Child}} at all.
> {code}
>   public void doSomething();
>     descriptor: ()V
>     flags: (0x0001) ACC_PUBLIC
>     Code:
>       stack=1, locals=1, args_size=1
>          0: aload_0
>          1: invokevirtual #20                 // Method Parent.getThing:()LThing;
>          4: checkcast     #22                 // class ThingImpl
>          7: invokevirtual #25                 // Method ThingImpl.call:()V
>         10: aconst_null
>         11: pop
>         12: return
> {code}
> This is causing now problems for Gradle plugins compiled against Grade 4.9 or before trying to run on Gradle 4.9, because we've made a change to an internal type (`ProjectInternal`) that ended up being referred to via this bug in compiled and released code. See https://github.com/gradle/gradle/issues/6027



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)