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

delegate is NullObject instance for closure metamethods invoked on null

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

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.4.0-rc-1
    • 5.0.0-alpha-3
    • None
    • None

    Description

      NullObject shouldn't be exposed outside groovy internals.

      This code example shows when NullObject leaks to application code:

      Object.metaClass.delegateClass = { 
          delegate?.getClass()
      }
      println null.delegateClass().name
      

      This prints out "org.codehaus.groovy.runtime.NullObject".

      -------

      possible solution:

      I assume that NullObject should be "filtered" in ClosureMetaMethod.

          public Object invoke(final Object object, Object[] arguments) {
              Closure cloned = (Closure) callable.clone();
              cloned.setDelegate(object);
      
              arguments = coerceArgumentsToClasses(arguments);
              return doCall.invoke(cloned, arguments);
          }
      

      replacing "cloned.setDelegate(object)" with

      cloned.setDelegate(!(object instanceof NullObject) ? object : null)
      

      would prevent the leak of NullObject in ClosureMetaMethod class.

      Attachments

        Issue Links

        Activity

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

          People

            emilles Eric Milles
            lhotari Lari Hotari
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment