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

Captured arguments in closures are not annotated with @Generated

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 3.0.0, 2.5.9
    • 2.5.10, 4.0.0-alpha-1, 3.0.1
    • Compiler
    • 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

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            aalmiray Andres Almiray
            aalmiray Andres Almiray
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 0.5h
                0.5h

                Slack

                  Issue deployment