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

Properties cannot be set through a @Delegate

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.7.2
    • 1.7.3, 1.8-beta-1
    • None
    • None

    Description

      When accessing a non-final property through a @Delegate as below, a ReadOnlyPropertyException is thrown.

      class DelegateTests extends GroovyTestCase {
          void testNonFinalPropertiesCanBeSet() {
              def foo = new Foo()
              foo.baz = "baz"
              assert foo.baz == "baz"
          }
      }
      
      class Foo {
          @Delegate Bar bar = new Bar()
      }
      
      class Bar {
          String baz
      }
      
      groovy.lang.ReadOnlyPropertyException: Cannot set readonly property: baz for class: test.Foo
      	at groovy.lang.MetaClassImpl.setProperty(MetaClassImpl.java:2406)
      	at groovy.lang.MetaClassImpl.setProperty(MetaClassImpl.java:3307)
      	at test.Foo.setProperty(DelegateTests.groovy)
      	at org.codehaus.groovy.runtime.InvokerHelper.setProperty(InvokerHelper.java:179)
      	at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.setProperty(ScriptBytecodeAdapter.java:483)
      	at test.DelegateTests.testNonFinalPropertiesCanBeSet(DelegateTests.groovy:11)

      Attachments

        Activity

          People

            roshandawrani Roshan Dawrani
            cdanielw Daniel Wiell
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: