You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (Jira)" <ji...@apache.org> on 2020/01/27 09:38:00 UTC

[jira] [Closed] (GROOVY-2913) Closure and binding with static finals from extended classes leads to an exception.

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

Paul King closed GROOVY-2913.
-----------------------------

> Closure and binding with static finals from extended classes leads to an exception.
> -----------------------------------------------------------------------------------
>
>                 Key: GROOVY-2913
>                 URL: https://issues.apache.org/jira/browse/GROOVY-2913
>             Project: Groovy
>          Issue Type: Sub-task
>          Components: groovy-runtime
>    Affects Versions: 1.5.6, 1.6-beta-1
>            Reporter: Hans Dockter
>            Priority: Major
>
> The following code produces an error
> {code}
> static final String A = 'a'
>     void testA() {
>         def closure = {
>             println A
>         }
>         closure()
>     }
>     void testC() {
>         println(A)
>         def closure = {
>             println AbstractClass.A
>         }
>         closure()
>   }
> class ConcreteClassTest extends AbstractClassTest {
>     static final String B = 'b'
>     void testB() {
>         println(B)
>         def closure = {
>             println B
>         }
>         closure()
>     }
> }
> {code}
> If I run ConcreteClassTest, testB and testC works fine but testA throws an exception.
> The stacktrace is:
> {noformat}
> groovy.lang.MissingPropertyException: No such property: A for class: ConcreteClass
> 	at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:49)
> 	at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:59)
> 	at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN(ScriptBytecodeAdapter.java:169)
> 	at AbstractClass.getProperty(AbstractClass.groovy)
> 	at org.codehaus.groovy.runtime.InvokerHelper.getProperty(InvokerHelper.java:172)
> 	at groovy.lang.Closure.getPropertyTryThese(Closure.java:200)
> 	at groovy.lang.Closure.getPropertyOwnerFirst(Closure.java:216)
> 	at groovy.lang.Closure.getProperty(Closure.java:186)
> 	at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.getGroovyObjectProperty(ScriptBytecodeAdapter.java:532)
> 	at AbstractClass$_testA_closure1.doCall(AbstractClass.groovy:28)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> 	at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
> 	at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:226)
> 	at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:248)
> 	at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnCurrentN(ScriptBytecodeAdapter.java:77)
> 	at AbstractClass$_testA_closure1.doCall(AbstractClass.groovy)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> 	at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
> 	at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:226)
> 	at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:248)
> 	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:754)
> 	at org.codehaus.groovy.runtime.InvokerHelper.invokePogoMethod(InvokerHelper.java:779)
> 	at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:759)
> 	at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN(ScriptBytecodeAdapter.java:167)
> 	at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeClosure(ScriptBytecodeAdapter.java:602)
> 	at AbstractClass.testA(AbstractClass.groovy:30)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> 	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:40)
> {noformat}



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