Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
1.1-rc-2
-
None
-
Windows XP
Java 1.6
built from subversion on 11/14
Description
When accessing the static metaClass method on a class, if it has a Custom MetaClass defined in the registry, it is overridden with an ExpandoMetaClass. This also affects already instantiated instances of the class.
If we call "println CustomMetaClassTest.metaClass", the existing CustomMetaClassTestMetaClass is replaced in the registry by an ExpandoMetaClass. Specfically, the static method GroovyDefaultMethods.getMetaClass(class c) creates an ExpandoMetaClass, and registers it, replacing whatever metaClass was already there.
Example problem scenario:
I create a custom metaclass for a legacy Java class, to make it more 'Groovy'-like. A user creates an instance of the Java class, and is using it. During the execution of his application, he calls "println LegacyClass.metaClass" so he can see which metaClass is being used. My custom metaClass is replaced by an expandoMetaclass, during runtime, and now method and property calls that my custom metaClass handled before the static call start to fail without warning.
I have added a test case to the CustomMetaClassTest to demonstrate this issue
----------------------------------
Method added to test case (revision 9152)
The last 2 asserts currently fail
----------------------------------
void testStaticMetaClass ()