Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-2503 MOP 2.0 design inflluencing issues
  3. GROOVY-2412

Need to access the metaClass of a subclass before receiving the dynamic methods that are added to the superclass

    XMLWordPrintableJSON

Details

    • Sub-task
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.5
    • None
    • groovy-runtime
    • None
    • Groovy Version: 1.5.0 JVM: 1.6.0_03-b05

    Description

      This script works:

      class Super
      {
      	def test2() { println "test2" }
      }
      
      Super.metaClass.test3 = { println "test3" }
      
      class Sub extends Super
      {
      	def test4() { println "test4"; super.test3() }
      }
      
      Sub.metaClass // Does not work without this line
      
      new Super().test2()
      new Super().test3()
      new Sub().test2()
      new Sub().test3()
      new Sub().test4()
      

      It outputs:

      test2
      test3
      test2
      test3
      test4
      test3
      

      But when I remove the commented line (Sub.metaClass), it does not work anymore. You get the following stacktrace:

      test2
      test3
      test2
      Caught: groovy.lang.MissingMethodException: No signature of method: Sub.test3() is applicable for argument types: () values: {}
              at Super.invokeMethod(test1.groovy)
              at test1.run(test1.groovy:18)
              at test1.main(test1.groovy)
      

      I think that calling Sub.metaClass should not have such a sideeffect.
      The script should work with or without it.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              rene.de.bloois René de Bloois
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: