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

Change In MetaClass Behavior

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.3.10
    • 2.3.11, 2.4.2
    • None
    • None

    Description

      The attached propertyaccess.zip contains the following:

      src/main/groovy/Widget.groovy
      package demo
      
      class Widget {
      
          static Integer someNumber = 42
      }
      
      src/test/groovy/WidgetSpec.groovy
      package demo
      
      class WidgetSpec extends spock.lang.Specification {
      
          void 'test property access'() {
              given:
              Widget.metaClass.getSomeNumber = {
                  2112
              }
      
              when:
              def widget = new Widget()
      
              then:
              widget.someNumber == 2112
          }
      }
      

      That test fails because widget.someNumber is 42. If I edit build.gradle and use Groovy 2.3.9 instead of 2.3.10, the test passes. Is this change in behavior intentional?

      Lari thinks that maybe https://github.com/groovy/groovy-core/commit/5e446eca2bae406619d8a6b115af6e4521bed2e4 is relevant.

      Attachments

        1. propertyaccess.zip
          51 kB
          Jeff Brown

        Issue Links

          Activity

            People

              melix Cédric Champeau
              brownj Jeff Brown
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: