You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Ian (Jira)" <ji...@apache.org> on 2021/04/26 16:29:00 UTC

[jira] [Created] (GROOVY-10059) Super Class Closure Can't Find Field when Any Method Overridden

Ian created GROOVY-10059:
----------------------------

             Summary: Super Class Closure Can't Find Field when Any Method Overridden
                 Key: GROOVY-10059
                 URL: https://issues.apache.org/jira/browse/GROOVY-10059
             Project: Groovy
          Issue Type: Bug
    Affects Versions: 4.0.0-alpha-3, 3.0.8
            Reporter: Ian


{noformat}
class A {
    private final boolean VAL = false
    Closure foo = {
        println VAL // Exception thrown from here
    }
}

class B {
    A a = new A() {} // Removing these braces makes it work as expected. Also fails if an actual method is overridden here
    def bar() {
        a.foo()
    }
}
new B().bar() // Running this throws exception
//new A().foo() // Running this instead works as expected{noformat}
Running this (script called OverrideFail.groovy) results in an exception:
{noformat}
Caught: groovy.lang.MissingPropertyException: No such property: VAL for class: B
Possible solutions: a
groovy.lang.MissingPropertyException: No such property: VAL for class: B
Possible solutions: a
	at A$_closure1.doCall(OverrideFail.groovy:4)
	at A$_closure1.doCall(OverrideFail.groovy)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at B.bar(OverrideFail.groovy:12)
	at B$bar.call(Unknown Source)
	at OverrideFail.run(OverrideFail.groovy:16)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
{noformat}



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