jira.codehaus.org

  • Log In Access more options
    • Online Help
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What?s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
  • groovy
  • GROOVY-2412

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

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Bug Bug
  • Status: Open Open
  • Priority: Major Major
  • Resolution: Unresolved
  • Affects Version/s: 1.5
  • Fix Version/s: 3.0
  • Component/s: None
  • Labels:
    None
  • Environment:
    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.

Issue Links

depends upon

Task - A task that needs to be done. GROOVY-2503 MOP 2.0 design inflluencing issues

  • Major - Major loss of function.
  • Open - The issue is open and ready for the assignee to start work on it.

Activity

  • All
  • Comments
  • Work Log
  • History
  • Activity
Hide
Permalink
René de Bloois added a comment - 18/Dec/07 8:45 AM

If I add ExpandoMetaClass.enableGlobally() it does work with and without the call to Sub.metaclass.

Maybe its by design that it fails without calling ExpandoMetaClass.enableGlobally(), but I still think that the behaviour should be consistent:

Accessing Sub.metaClass should have no influence on the success or failure of the script.

Show
René de Bloois added a comment - 18/Dec/07 8:45 AM If I add ExpandoMetaClass.enableGlobally() it does work with and without the call to Sub.metaclass. Maybe its by design that it fails without calling ExpandoMetaClass.enableGlobally(), but I still think that the behaviour should be consistent: Accessing Sub.metaClass should have no influence on the success or failure of the script.

People

  • Assignee:
    Unassigned
    Reporter:
    René de Bloois
Vote (0)
Watch (1)

Dates

  • Created:
    18/Dec/07 6:07 AM
    Updated:
    16/Oct/08 1:37 PM
  • Atlassian JIRA (v5.0.4#731-sha1:3aa7374)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Codehaus. Try JIRA - bug tracking software for your team.