Groovy
  1. Groovy
  2. GROOVY-4069

Custom constructors added via metaclass are sometimes not cleaned up

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.7.1
    • Fix Version/s: 1.7.2, 1.8-beta-1
    • Component/s: None
    • Labels:
      None

      Description

      There seems to be an issue with constructors added via metaclass and cleanup:

      class MetaClassMagicTests extends GroovyTestCase {
          void testIt() {
              ExpandoMetaClass.enableGlobally()
              
              // Child.metaClass // uncomment and everything works
              
              // Save the old meta class
              def oldMetaClass = Parent.metaClass
              
              // Install a new one
              def emc = new ExpandoMetaClass(Parent, true, true)
              emc.initialize()
              GroovySystem.metaClassRegistry.setMetaClass(Parent, emc)
              
              // Install a map based constructor
              emc.constructor = { Map m -> Parent.newInstance() }
              
              // Parent constructor is used, all good
              assert new Child([:]) instanceof Parent
              
              // Reinstate the old meta class
              GroovySystem.metaClassRegistry.removeMetaClass(Parent) 
              GroovySystem.metaClassRegistry.setMetaClass(Parent, oldMetaClass)
      
              // This fails, this calls the custom constructor from above and returns an instance of Parent
              assert new Child([:]) instanceof Child
          }
          
      }
      
      class Parent { def a }
      class Child extends Parent { def b }
      
      1. 4069_v18x_Patch.txt
        8 kB
        Roshan Dawrani
      2. V2_4069_v18x_Patch.txt
        6 kB
        Roshan Dawrani

        Activity

        No work has yet been logged on this issue.

          People

          • Assignee:
            Roshan Dawrani
            Reporter:
            Luke Daley
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development