Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
3.0.0, 2.5.9
-
None
Description
When a closure captures arguments, say from an enclosing method, these arguments are exposed via public getters. these getters should be annotated with `@Generated`.
The following class
class GroovyClosureClassTarget { // assertEmpty() Closure<String> c(String arg ) { def closureVar = { arg // assertFullyCovered() } closureVar // assertFullyCovered() } static void main(String[] args) { Closure cls = new GroovyClosureClassTarget().c('var') cls() == 'var' } }
Is compiled to the following bytecode
... public Closure<String> c(String arg) { final Reference arg = new Reference(arg); CallSite[] var3 = $getCallSiteArray(); final class _c_closure1 extends Closure implements GeneratedClosure { public _c_closure1(Object _outerInstance, Object _thisObject) { CallSite[] var4 = $getCallSiteArray(); super(_outerInstance, _thisObject); } public Object doCall(Object it) { CallSite[] var2 = $getCallSiteArray(); return arg.get(); } // missing annotation here!! public String getArg() { CallSite[] var1 = $getCallSiteArray(); return (String)ShortTypeHandling.castToString(arg.get()); } @Generated public Object doCall() { CallSite[] var1 = $getCallSiteArray(); return this.doCall((Object)null); } } Object closureVar = new _c_closure1(this, this); return (Closure)ScriptBytecodeAdapter.castToType(closureVar, Closure.class); } ...
Attachments
Issue Links
- links to