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

        Mark Thomas made changes -
        Workflow jira [ 12970679 ] Default workflow, editable Closed status [ 12978474 ]
        Mark Thomas made changes -
        Project Import Mon Apr 06 02:11:23 UTC 2015 [ 1428286283443 ]
        Mark Thomas made changes -
        Workflow jira [ 12733020 ] Default workflow, editable Closed status [ 12744853 ]
        Mark Thomas made changes -
        Project Import Sun Apr 05 13:32:57 UTC 2015 [ 1428240777691 ]
        Paul King made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Roshan Dawrani made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 1.8-beta-1 [ 16013 ]
        Resolution Fixed [ 1 ]
        Fix Version/s 1.7.2 [ 16237 ]
        Roshan Dawrani made changes -
        Assignee Roshan Dawrani [ roshandawrani ]
        Roshan Dawrani made changes -
        Attachment V2_4069_v18x_Patch.txt [ 47741 ]
        Roshan Dawrani made changes -
        Attachment 4069_v18x_Patch.txt [ 47716 ]
        Luke Daley made changes -
        Field Original Value New Value
        Link This issue is related to GRAILS-5883 [ GRAILS-5883 ]
        Luke Daley created 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