Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
1.7.1
-
None
-
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 }