groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Lóránt Pintér (JIRA) <j...@apache.org>
Subject [jira] [Created] (GROOVY-8732) @CompileStatic allows access to private
Date Mon, 06 Aug 2018 12:27:00 GMT
Lóránt Pintér created GROOVY-8732:
-------------------------------------

             Summary: @CompileStatic allows access to private 
                 Key: GROOVY-8732
                 URL: https://issues.apache.org/jira/browse/GROOVY-8732
             Project: Groovy
          Issue Type: Bug
          Components: Static compilation
    Affects Versions: 2.5.1, 3.0.0-alpha-3, 2.6.0-alpha-4, 2.4.15
            Reporter: Lóránt Pintér


{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)

Mime
View raw message