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

Strange behavior on property setter

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 1.0-JSR-3
    • 1.5.2
    • None
    • None
    • Groovy jsr-03, java version "1.5.0_05", winXP

    Description

      Try this:

      class Foo {
        private _xxx
      
        public void setBar(b) {
          println "before setting"
          _xxx = b
          println "after setting"  
        }
      }
      
      def x = new Foo()
      
      x.bar = 1
      x.bar = 2
      

      When run, the output is:

      C:\Temp>groovy settertest.groovy
      before setting
      after setting
      before setting
      after setting
      Caught: groovy.lang.GroovyRuntimeException: Cannot read property: bar

      even though the property bar was never read. If you add e.g.
      println "goodbye"
      as the last line of the script, the exception does not occur.

      Attachments

        Issue Links

          Activity

            People

              paulk Paul King
              antti.karanta@napa.fi Antti Karanta
              Votes:
              1 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: