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

Call site of static property is not updated after meta class is changed

    XMLWordPrintableJSON

Details

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

    Description

      class StaticPropertyBug extends GroovyTestCase {
      
          MetaClassRegistry registry
          MetaClass originalMetaClass
      
          void setUp() {
              registry = GroovySystem.metaClassRegistry
              originalMetaClass = registry.getMetaClass(StaticPropertyFoo)
          }
      
          void tearDown() {
              registry.setMetaClass(StaticPropertyFoo, originalMetaClass)
          }
      
          void testCallSiteShouldBeUpdatedAfterProxyMetaClassIsSet() {
              def getFoo = { -> StaticPropertyFoo.bar }
      
              assert 'foo' == StaticPropertyFoo.bar
              assert 'foo' == getFoo()
      
              MetaClass mc = new StaticPropertyClassProxyMetaClass(registry, StaticPropertyFoo, originalMetaClass)
              registry.setMetaClass(StaticPropertyFoo, mc)
      
              assert 'static' == StaticPropertyFoo.bar
              assert 'static' == getFoo() // failed here
          }
      
          void testCallSiteShouldBeUpdatedAfterOriginalMetaClassIsRestored() {
              def getFoo = { -> StaticPropertyFoo.bar }
      
              MetaClass mc = new StaticPropertyClassProxyMetaClass(registry, StaticPropertyFoo, originalMetaClass)
              registry.setMetaClass(StaticPropertyFoo, mc)
      
              assert 'static' == StaticPropertyFoo.bar
              assert 'static' == getFoo()
      
              registry.setMetaClass(StaticPropertyFoo, originalMetaClass)
      
              assert 'foo' == StaticPropertyFoo.bar
              assert 'foo' == getFoo() // failed here
          }
      
      }
      
      class StaticPropertyFoo {
          static bar = 'foo'
      }
      
      class StaticPropertyClassProxyMetaClass extends ProxyMetaClass {
          StaticPropertyClassProxyMetaClass(MetaClassRegistry metaClassRegistry, Class aClass, MetaClass adaptee) {
              super(metaClassRegistry, aClass, adaptee)
          }
          public Object getProperty(Class aClass, Object object, String property, boolean b, boolean b1) {
              'static'
          }
      }
      

      A patch for this bug is included.

      Attachments

        1. StaticProperty_1.patch
          3 kB
          Johnny Jian

        Activity

          People

            blackdrag Jochen Theodorou
            johnnyjian Johnny Jian
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: