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

MethodClosure doesn't support variable arguments method

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

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 1.0-beta-9
    • 1.0
    • None
    • None
    • Any

    Description

      expression

      new org.codehaus.groovy.runtime.MethodClosure(object,"myMethod")

      never makes closure with support for variable arguments, even if myMethod is defined as:

      public String myMethod(Object[] args)

      { ... }

      I have located the problem in Groovy source code.
      In MethodClosure.java doCall is defined as:

      protected Object doCall(Object arguments) {
      ...
      }

      but lang.groovy.Closure constructor turns on variable argument support only if type of last argument in doCall is Object [].

      A workaround is to use expression:

      new Closure(object) {
      public String doCall(Object[] args)

      { return object.myMethod(args); }

      }

      Attachments

        Issue Links

        Activity

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

          People

            guillaume Guillaume Sauthier
            nebojsa Nebojsa Vasiljevic
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment