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

successive metaclass modification for class then instance fails.

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.7.1
    • 1.7.3, 1.8-beta-1
    • groovy-jdk
    • None
    • groovy 1.7, jdk 1.6.20, win 7

    Description

      define a groovy class (an empty class declaration will do).

      class TestClass0 {}

      Muck with the metaclass using the class and an instance. the second closure assignment throws an exception (java.lang.ClassCastException: groovy.lang.MetaClassImpl cannot be cast to groovy.lang.GroovyObject at org.codehaus.groovy.runtime.HandleMetaClass.replaceDelegate(HandleMetaClass.java:71)).

      void testSomething1() {
      def inst = new TestClass0();
      TestClass0.metaClass.addedMethod0 =

      { return 'hello0'}

      inst.metaClass.addedMethod1 =

      { return 'hello1'}

      }

      note that simply changing the order of the closure assignments executes without throwing exceptions.

      Attachments

        Activity

          People

            roshandawrani Roshan Dawrani
            rovrevik Ryan Ovrevik
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: