Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
4.0.0, 2.5.22, 3.0.16
-
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
- is caused by
-
GROOVY-10329 import static star: add support for static callable property
- Closed
- is related to
-
GROOVY-3945 Statically imported closure field is not resolved
- Closed
-
GROOVY-7490 CompileStatic confuses statically importing an instance and statically importing a method
- Closed
-
GROOVY-7701 org.codehaus.groovy.runtime.typehandling.GroovyCastException in Groovy ".with { ... }" - Block
- Closed
-
GROOVY-8389 Static import of a property messes with instance method
- Closed
-
GROOVY-9655 Groovy 3.0.5 regression with the "with" keyword
- Closed
-
GROOVY-9683 Changed behavior of delegates in 2.5.13
- Closed
-
GROOVY-9768 Changed behavior of delegates in 4.0.0
- Closed