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

Cannot restore the original metaclass after intercepting static method

    XMLWordPrintableJSON

Details

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

    Description

      import groovy.sql.Sql
      import java.sql.SQLException

      class TestStaticMethod extends GroovyTestCase {

      void testSqlNewInstance() {
      shouldFail(SQLException)

      { SqlNewInstance.get() }

      MetaClassRegistry registry = GroovySystem.metaClassRegistry
      def original = registry.getMetaClass(Sql)
      def mc = new ClassProxyMetaClass(registry, Sql, original)
      registry.setMetaClass(Sql, mc)

      assert 'static' == SqlNewInstance.get()

      registry.setMetaClass(Sql, original)

      shouldFail(SQLException) { SqlNewInstance.get() }

      // failed here
      }

      }

      class ClassProxyMetaClass extends ProxyMetaClass {
      ClassProxyMetaClass(MetaClassRegistry metaClassRegistry, Class aClass, MetaClass adaptee)

      { super(metaClassRegistry, aClass, adaptee) }

      public Object invokeStaticMethod(final Object aClass, final String method, final Object[] arguments)

      { 'static' }

      }

      class SqlNewInstance {
      static get()

      { Sql.newInstance('') }

      }

      Attachments

        1. Groovy3426_1.patch
          5 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: