Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-11056

modified behavior of variable resolution within Closure

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 4.0.0, 2.5.22, 3.0.16
    • 2.5.23, 3.0.18, 4.0.13
    • groovy-runtime
    • None

    Description

      Groovy stopped seeing statically imported instances when called within Closure within Closure. And instead it thinks it is some method call.

      Below is the example to repro. At the moment it affects all our users written test scripts and we rolled back to 3.0.15 where behavior is still as expected.

      Tried various closure resolution strategies to no result 

      import static org.testingisdocumenting.webtau.persona.ReproPersonaList.Admin
      
      class ClosureResolveRepro {
          static void main(String[] args) {
              def LocalAdmin = new ReproPersona("local-admin")
      
              wrapper {
                  LocalAdmin { // <-- no issue here as it can correctly see LocalAdmin
                  }
              }
      
              wrapper {
                  Admin { // <--- issue is here, for some reason it doesn't see statically imported instance. It works as expected in 3.0.15
                  }
              }
          }
      
          private static void wrapper(Closure code) { // this wrapper is required to reproduce 
              code.run()
          }
      }
       
      person: local-adminException in thread "main" groovy.lang.MissingMethodException: No signature of method: org.testingisdocumenting.webtau.persona.ClosureResolveRepro$_main_closure2.Admin() is applicable for argument types: (org.testingisdocumenting.webtau.persona.ClosureResolveRepro$_main_closure2$_closure4) values: [org.testingisdocumenting.webtau.persona.ClosureResolveRepro$_main_closure2$_closure4@40f08448]Possible solutions: find(), dump(), find(), dump(), any(), any() at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:380) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1035) at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:73) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:51) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:171) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:185) at org.testingisdocumenting.webtau.persona.ClosureResolveRepro$_main_closure2.doCall(ClosureResolveRepro.groovy:31) at org.testingisdocumenting.webtau.persona.ClosureResolveRepro$_main_closure2.doCall(ClosureResolveRepro.groovy) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:107) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:323) at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:274) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1035) at groovy.lang.Closure.call(Closure.java:412) at groovy.lang.Closure.call(Closure.java:406) at groovy.lang.Closure.run(Closure.java:493) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:107) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:323) at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:274) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1035) at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:38) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47) at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:53) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:130) at org.testingisdocumenting.webtau.persona.ClosureResolveRepro.wrapper(ClosureResolveRepro.groovy:37) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:107) at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite$StaticMetaMethodSiteNoUnwrapNoCoerce.invoke(StaticMetaMethodSite.java:149) at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.callStatic(StaticMetaMethodSite.java:100) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallStatic(CallSiteArray.java:55) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:217) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:231) at org.testingisdocumenting.webtau.persona.ClosureResolveRepro.main(ClosureResolveRepro.groovy:30)
      

       

      class ReproPersona {
          private String id
      
          ReproPersona(String id) {
              this.id = id
          }
      
          void call(Closure code) {
              println "person: $id"
          }
      } 
      class ReproPersonaList {
          public static def Admin = new ReproPersona("admin")
      } 

       

      Attachments

        Issue Links

          Activity

            People

              emilles Eric Milles
              ninside Mykola Golubyev
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: