Non-reified Ruby classes can't be to_java :object -------------------------------------------------
Key: JRUBY-4669 URL: http://jira.codehaus.org/browse/JRUBY-4669 Project: JRuby Issue Type: Bug Components: Java Integration Affects Versions: JRuby 1.5 Reporter: Charles Oliver Nutter Assignee: Charles Oliver Nutter Fix For: JRuby 1.5 I added the ability recently to to_java/toJava a RubyClass and get the actual native backing store's class (or in JI classes, to get the real java.lang.Class). However this doesn't work for classes that have not been reified, like user-defined classes: {noformat} ~/projects/jruby ➔ jruby -rjava -e "class Foo; end; Foo.to_java" :1:in `to_java': cannot convert instance of class org.jruby.RubyClass to class java.lang.Object (TypeError) from :1 {noformat} The trivial fix I have for this is to not expose the backing store class unless it's a Java proxy; it's not great, but we have a troublesome duality here...should a non-Java Ruby class to_java(object) to a RubyClass object or a java.lang.Class object? This came up for a user on IRC trying to use ScriptingContainer.runScriptlet to get a RubyClass instance. The error that resulted: http://gist.github.com/339537 Here's the temporary patch for now: {noformat} diff --git a/src/org/jruby/RubyClass.java b/src/org/jruby/RubyClass.java index e57c5bc..6940a49 100644 --- a/src/org/jruby/RubyClass.java +++ b/src/org/jruby/RubyClass.java @@ -1322,7 +1322,7 @@ public class RubyClass extends RubyModule { JavaClass javaClass = (JavaClass)callMethod("java_class"); returnClass = (Class)javaClass.getValue(); } else { - returnClass = getReifiedClass(); + return this; } } {noformat} -- 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