Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-2503 MOP 2.0 design inflluencing issues
  3. GROOVY-2913

Closure and binding with static finals from extended classes leads to an exception.

    XMLWordPrintableJSON

Details

    • Sub-task
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.5.6, 1.6-beta-1
    • None
    • groovy-runtime
    • None

    Description

      The following code produces an error

      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()
          }
      }
      

      If I run ConcreteClassTest, testB and testC works fine but testA throws an exception.

      The stacktrace is:

      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)
      

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              hans_d Hans Dockter
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: