[ https://issues.apache.org/jira/browse/GROOVY-11056?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17722905#comment-17722905 ]
Eric Milles commented on GROOVY-11056: -------------------------------------- Here is where {{StaticImportVisitor}} finds the static field import, but chooses to skip: {code:java} String name = method.getText(); Map<String, ImportNode> staticImports = currentClass.getModule().getStaticImports(); // look for one of these: // import static MyClass.field [as alias] // import static MyClass.method [as alias] // import static MyClass.property [as alias] // when resolving implicit-this call name(args) if (staticImports.containsKey(name)) { ImportNode importNode = staticImports.get(name); expression = findStaticMethod(importNode.getType(), importNode.getFieldName(), args); if (expression != null) { return expression; } if (!inClosure && !inLeftExpression) { // *** inClosure is true for "Admin" *** expression = findStaticPropertyOrField(importNode.getType(), importNode.getFieldName()); if (expression != null) { // assume name refers to a callable static field/property MethodCallExpression call = new MethodCallExpression(expression, "call", args); call.setImplicitThis(false); return call; } } } {code} https://github.com/apache/groovy/blame/c793a80e9160ca31a225948f256b3de953e6e1da/src/main/java/org/codehaus/groovy/control/StaticImportVisitor.java#L450 > modified behavior of variable resolution within Closure > -------------------------------------------------------- > > Key: GROOVY-11056 > URL: https://issues.apache.org/jira/browse/GROOVY-11056 > Project: Groovy > Issue Type: Bug > Components: groovy-runtime > Affects Versions: 3.0.16 > Reporter: Mykola Golubyev > Assignee: Eric Milles > Priority: Major > > 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 > {code:java} > 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() > } > } > {code} > {code:java} > 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) > {code} > > {code:java} > class ReproPersona { > private String id > ReproPersona(String id) { > this.id = id > } > void call(Closure code) { > println "person: $id" > } > } {code} > {code:java} > class ReproPersonaList { > public static def Admin = new ReproPersona("admin") > } {code} > -- This message was sent by Atlassian Jira (v8.20.10#820010)