Declaration of certain method name (setJavaObject(Xxx x)) will throw an 
exception using BSF
-------------------------------------------------------------------------------------------

                 Key: JRUBY-1562
                 URL: http://jira.codehaus.org/browse/JRUBY-1562
             Project: JRuby
          Issue Type: Bug
          Components: Core Classes/Modules
    Affects Versions: JRuby 1.0.2
         Environment: Windows XP SP2
            Reporter: Sebastien AUVRAY
            Priority: Minor
         Attachments: JRubyBSFProxyTest.java, MyJObject.java

When defining the method _setJavaObject(SomeObject so)_ in Java and using this 
Java Object from Ruby (in my case extending it), The following exception will 
occur:

{noformat}
Exception: <script>:5:in `__jcreate!': invokee not a java object (TypeError)
        from 
file:/D:/sa/bin/jruby-1.0.2/lib/jruby.jar!/builtin/javasupport/proxy/concrete.rb:24:in
 `initialize'
        from 
file:/D:/sa/bin/jruby-1.0.2/lib/jruby.jar!/builtin/javasupport/proxy/concrete.rb:7:in
 `new'
        from 
file:/D:/sa/bin/jruby-1.0.2/lib/jruby.jar!/builtin/javasupport/proxy/concrete.rb:7:in
 `new'
        from <script>:1
        ...internal jruby stack elided...
        from org.jruby.Ruby.eval(Ruby.java:278)
        from org.jruby.Ruby.evalScript(Ruby.java:271)
        from org.jruby.javasupport.bsf.JRubyEngine.eval(JRubyEngine.java:103)
        from org.apache.bsf.BSFManager$5.run(Unknown Source)
        from java.security.AccessController.doPrivileged(Native Method)
        from org.apache.bsf.BSFManager.eval(Unknown Source)
        from TestSetJavaObject.main(TestSetJavaObject.java:31)
        from sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        from 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        from 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        from java.lang.reflect.Method.invoke(Method.java:324)
        from 
com.intellij.rt.execution.application.AppMain.main(AppMain.java:90) 
{noformat} 

It seems as if _java_object=_ which is used internally is messing around.

To reproduce:

{code:title=JRubyBSFProxyTest.java|borderStyle=solid}
import org.apache.bsf.BSFManager;
import junit.framework.TestCase;

public class JRubyBSFProxyTest extends TestCase {

    private static final String RUBY_CODE = "require 'java'\n" +
            "\n" +
            "include_class \"MyJObject\"\n" +
            "\n" +
            "class MyOwnJavaInRuby < MyJObject\n" +
            "\t\n" +
            "end";

    public static void testSetJavaObjectDoesNotRaiseException() {
        try {
            BSFManager.registerScriptingEngine("ruby", 
"org.jruby.javasupport.bsf.JRubyEngine", new String[]{"rb"});
            BSFManager manager = new BSFManager();

            manager.exec("ruby", "my_own_java_in_ruby.rb", -1, -1, RUBY_CODE);

            //--- Make a new ruby object
            String expr = "MyOwnJavaInRuby.new";
            MyJObject ruby = (MyJObject) manager.eval("ruby", 
"my_own_java_in_ruby.rb", -1, -1, expr);

        } catch (Exception e) {
            e.printStackTrace();
            fail("public void setJavaObject(String myJavaObject) should not 
raise an exception");
        }
    }

}
{code} 

{code:title=MyJObject.java|borderStyle=solid}
public class MyJObject {

    public void setJavaObject(String myJavaObject) {
    }

}
{code} 

Commenting out setJavaObject (or use different name) method will make things 
work.

-- 
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

Reply via email to