Issue Type: Bug Bug
Affects Versions: JRuby 1.7.0.pre1, JRuby 1.6.7
Assignee: Unassigned
Components: Java Integration
Created: 19/Jul/12 11:10 AM
Description:

This is causing us to use runScriptlet in the Ruboto internals, but the behavior is the same using OS X + Apple Java 6.

We reopen a Java class to define Ruby methods on it, and then call these methods directly from Java. Here is an example:

import org.jruby.embed.ScriptingContainer;

class ReopenJavaClass {
    public ReopenJavaClass() {}

    public static void main(String[] args) throws Exception {
        ScriptingContainer sc = new ScriptingContainer(org.jruby.embed.LocalContextScope.SINGLETON,
                org.jruby.embed.LocalVariableBehavior.TRANSIENT);
        sc.put("ReopenJavaClass", sc.runScriptlet("Java::ReopenJavaClass"));
        sc.runScriptlet("class ReopenJavaClass ; def ruby_method ; puts 'Success!' ; end ; end");
        sc.callMethod(new ReopenJavaClass(), "ruby_method");
    }
}

When we run this we get the following exception:

$ javac -cp .:../jruby/dist/jruby-complete-1.7.0.preview2.dev.jar -d tmp ReopenJavaClass.java 
$ java -cp .:../jruby/dist/jruby-complete-1.7.0.preview2.dev.jar ReopenJavaClass
NoMethodError: undefined method `ruby_method' for main:Object
Exception in thread "main" org.jruby.embed.InvokeFailedException: (NoMethodError) undefined method `ruby_method' for main:Object
	at org.jruby.embed.internal.EmbedRubyObjectAdapterImpl.call(EmbedRubyObjectAdapterImpl.java:296)
	at org.jruby.embed.internal.EmbedRubyObjectAdapterImpl.callMethod(EmbedRubyObjectAdapterImpl.java:241)
	at org.jruby.embed.ScriptingContainer.callMethod(ScriptingContainer.java:1367)
	at ReopenJavaClass.main(ReopenJavaClass.java:11)
Caused by: org.jruby.exceptions.RaiseException: (NoMethodError) undefined method `ruby_method' for main:Object

Are we using callMethods wrongly? Any help on this would be absolutely great!

Environment: OS X 10.7.4 + Apple Java 1.6.0_33-b03-424-11M3720
Android 2.3 and 4.0
Fix Versions: JRuby 1.7.0.pre2
Project: JRuby
Priority: Major Major
Reporter: Uwe Kubosch
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators.
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

Reply via email to