[jira] [Commented] (GROOVY-8732) @CompileStatic refers to private field in parent class

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[jira] [Commented] (GROOVY-8732) @CompileStatic refers to private field in parent class

JIRA jira@apache.org

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

ASF GitHub Bot commented on GROOVY-8732:
----------------------------------------

GitHub user paulk-asert opened a pull request:

    https://github.com/apache/groovy/pull/781

    GROOVY-8732: @CompileStatic refers to private field in parent class

    Currently JavaBean style getters aren't recognised
    before some preliminary provisions are made for the
    case of accessing the private field in places where that
    is allowed. The change is just not to proceed with those
    provisions if the JavaBean getter is detected.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/paulk-asert/groovy groovy8732

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/groovy/pull/781.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #781
   
----
commit 2b4c33317f34d52c5fbeb0846639597a5f6b86fe
Author: Paul King <paulk@...>
Date:   2018-08-09T08:12:08Z

    GROOVY-8732: @CompileStatic refers to private field in parent class
    Currently JavaBean style getters aren't recognised
    before some preliminary provisions are made for the
    case of accessing the private field in places where that
    is allowed. The change is just not to proceed with those
    provisions if the JavaBean getter is detected.

----


> @CompileStatic refers to 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)