getMetaClass and metaclass should not be used to define methods, ever.
----------------------------------------------------------------------
Key: JRUBY-2469
URL: http://jira.codehaus.org/browse/JRUBY-2469
Project: JRuby
Issue Type: Bug
Components: Core Classes/Modules
Reporter: Ola Bini
Priority: Critical
This seems to be the real cause for both JRUBY-1866 and JRUBY-2388. We have a
pattern that was much more common earlier, but has been fixed mostly with
annotations. The pattern was to use something.getMetaClass() to define
singleton methods. This includes module methods. The problem is that this idiom
only works if there already exists a singleton class for that object.
{noformat}
obj.getMetaClass().defineAnnotatedMethods(Some.class);
{noformat}
Will be wrong in most cases. As luck would have it, the places we do this
generally extend Enumerable before defining annotated methods. But that is pure
chance.
The correct idiom is to use getSingletonClass(). This also seems to be the
trouble with the meta-argument to the JRubyMethod annotation. As far as I can
tell, it uses the .metaClass field of RubyObject, which have the same problem
as getMetaClass().
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email