Details
-
Type:
Bug
-
Status:
Open
-
Priority:
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
-
GROOVY-2503
MOP 2.0 design inflluencing issues
-
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.