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

invoking Closure property like method fails because of doCall/call asynchronity

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 2.4.8
    • groovy-runtime
    • None

    Description

      In this code:

      class Lol {
          def clo = {
              println "arg $it"
          }.memoize()
      }
      

      a new Lol().clo("my arg") fails, even though it should work. Looking at the error message it can be seen, that the runtime tries to do a doCall, while the MemoizeFunction that is stored in clo does not have that method (instead it overrides call(Object[])). Looking at MetaClassImpl you can find the following piece of code around line 1121:

              if (value instanceof Closure) {  // This test ensures that value != this If you ever change this ensure that value != this
                  Closure closure = (Closure) value;
                  MetaClass delegateMetaClass = closure.getMetaClass();
                  return delegateMetaClass.invokeMethod(closure.getClass(), closure, CLOSURE_DO_CALL_METHOD, originalArguments, false, fromInsideClass);
              }
      

      That code clearly tries to do doCall, instead of call. It is to be assumed that code following this does not check for both variants equally.

      Proposed fix: use call instead of doCall

      Attachments

        Issue Links

          Activity

            People

              jwagenleitner John Wagenleitner
              blackdrag Jochen Theodorou
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: