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

Properties of @Delegate fields are preferred to those in the owning class

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.4.10
    • Fix Version/s: 2.4.11
    • Component/s: Compiler
    • Labels:
      None

      Description

      Example:

      class Foo {
          String pls
          @groovy.lang.Delegate
          Bar bar
      }
      
      class Bar { 
          String pls        
      }
      assert new Foo(pls: 'ok').pls == 'ok'
      

      Running the code above results in the following exception:

      java.lang.NullPointerException: Cannot set property 'pls' on null object
      

      Delegation of properties should behave the the same way as delegation of methods i.e. properties of delegates should not take precedence over properties declared in the owning class.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                shils Shil Sinha
                Reporter:
                shils Shil Sinha
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: