Scott Murphy Heiberg created GROOVY-12610:
---------------------------------------------
Summary: STC accepts access to a private superclass field through
a nested subclass under @TypeChecked, which fails at run time
Key: GROOVY-12610
URL: https://issues.apache.org/jira/browse/GROOVY-12610
Project: Groovy
Issue Type: Bug
Affects Versions: 5.0.8, 4.0.33, 6.0.0
Reporter: Scott Murphy Heiberg
{code:groovy}
class Base {
private String z = 'x'
@groovy.transform.TypeChecked
static class Sub extends Base {
def m() { this.z } // also: z, super.z, closures, lambdas, writes,
that.z
}
}
new Base.Sub().m()
{code}
Actual: the code compiles, then fails with MissingPropertyException: No such
property: z for class: Base$Sub. Dynamic Groovy fails the same way.
Expected: under @TypeChecked, a compile error "No such property: z for class:
Base$Sub", as already reported when Base and Sub are both nested in another
class. @CompileStatic keeps accepting the code, because it accesses the field
directly from a nest-mate.
Cause: the type checker uses the nest-mate accessibility rule of static
compilation for @TypeChecked code too. Type-checked code is dispatched
dynamically, and the metaclass of a subclass does not list a private field of
its superclass.
Seen in 4.0.33, 5.0.8 and 6.0.0.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)