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

Call site of POJO 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 POJOCallSiteBug extends GroovyTestCase {
      
          MetaClassRegistry registry
          MetaClass originalMetaClass
      
          void setUp() {
              registry = GroovySystem.metaClassRegistry
              originalMetaClass = registry.getMetaClass(POJOCallSiteBugFoo)
          }
      
          void tearDown() {
              registry.setMetaClass(POJOCallSiteBugFoo, originalMetaClass)
          }
      
          void testPOJOCallSiteShouldBeUpdatedAfterMetaClassIsChanged() {
              def foo = { s -> s.foo() }
              def s = new POJOCallSiteBugFoo()
      
              POJOCallSiteBugFoo.metaClass = new POJOCallSiteBugProxyMetaClass(registry, POJOCallSiteBugFoo, originalMetaClass, 'foo')
              assert 'foo' == s.foo()
              assert 'foo' == foo(s)
      
              POJOCallSiteBugFoo.metaClass = new POJOCallSiteBugProxyMetaClass(registry, POJOCallSiteBugFoo, originalMetaClass, 'test')
              assert 'test' == s.foo()
              assert 'test' == foo(s) // failed here
          }
      
          void testPOJOPropertyCallSiteShouldBeUpdatedAfterMetaClassIsChanged() {
              def bar = { foo -> foo.bar }
              def foo = new POJOCallSiteBugFoo()
      
              assert 'bar' == foo.bar
              assert 'bar' == bar(foo)
      
              foo.metaClass = new POJOCallSiteBugProxyMetaClass(registry, POJOCallSiteBugFoo, originalMetaClass, 'test')
      
              assert 'test' == foo.bar
              assert 'test' == bar(foo) // failed here
          }
      
          void testPOJOFieldCallSiteShouldBeUpdatedAfterMetaClassIsChanged() {
              def field = { foo -> foo.field }
              def foo = new POJOCallSiteBugFoo()
      
              assert 'field' == foo.field
              assert 'field' == field(foo)
      
              foo.metaClass = new POJOCallSiteBugProxyMetaClass(registry, POJOCallSiteBugFoo, originalMetaClass, 'test')
      
              assert 'test' == foo.field
              assert 'test' == field(foo) // failed here
          }
      
      }
      
      class POJOCallSiteBugProxyMetaClass extends ProxyMetaClass {
          String result
          POJOCallSiteBugProxyMetaClass(MetaClassRegistry metaClassRegistry, Class aClass, MetaClass adaptee, String result) {
              super(metaClassRegistry, aClass, adaptee)
              this.result = result
          }
          public Object invokeMethod(final Object object, final String methodName, final Object[] arguments) {
              result
          }
          public Object getProperty(Class aClass, Object object, String property, boolean b, boolean b1) {
              result
          }
      }
      

      POJOCallSiteBugFoo.java:

      public class POJOCallSiteBugFoo {
      
          public String field = "field";
      
          public String getBar() {
              return "bar";
          }
      
      }
      

      And a patch is included.

      Attachments

        1. POJOCallSite.patch
          12 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: