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

@Delegate not working when it refers to a Map

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.6
    • 1.6.4, 1.7-beta-1
    • None
    • None

    Description

      If you use the @Delegate to mark a Map as a Delegate you'll get an error:

      java.lang.NullPointerException: Cannot invoke method put() on null object

      It can be illustrated with this example:

      class Test {
      @Delegate Map mp
      }

      def t = new Test(mp: new HashMap())

      println t.keySet()

      I originally noticed it when trying it with a GroovyRowResult (same error as above):

      import groovy.sql.GroovyRowResult

      class DelegateRowResult {
      @Delegate GroovyRowResult row
      String foo
      }

      DelegateRowResult d = new DelegateRowResult( foo: "Boo")
      println "$d.foo"

      Attachments

        Activity

          People

            roshandawrani Roshan Dawrani
            rickcr Rick Reumann
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: