ruby2java needs to cast return values to java.lang.String
---------------------------------------------------------

                 Key: JRUBY-3801
                 URL: http://jira.codehaus.org/browse/JRUBY-3801
             Project: JRuby
          Issue Type: Bug
          Components: Java Integration
    Affects Versions: JRuby 1.3.1
         Environment: OS X 10.5.7 on G4
            Reporter: Ian Dees


Given the following Ruby file:

{code:title=sample.rb}
Sample
  def bar
    "Hello from Ruby"
  end

  if defined? Ruby2Java
    signature :bar, [] => java.lang.String
  end
end
{code}

... and the following Java file:

{code:title=SampleTest.java}
public class SampleTest {
    public static void main(String args[]) {
        Sample s = new Sample();
    }
}
{code}

When you run:

{noformat}
ruby2java Sample sample.rb
java -cp jruby.jar:. SampleTest
{noformat}

The following error occurs:

{noformat}
Exception in thread "main" java.lang.VerifyError: (class: Sample, method: bar 
signature: ()Ljava/lang/String;) Illegal type in constant pool
        at SampleTest.main(SampleTest.java:3)
{noformat}

Per Charlie, here's the {{bar}} method, disassembled:

{noformat}
public java.lang.String bar();
  Code:
   Stack=4, Locals=2, Args_size=1
   0:   aload_0
   1:   dup
   2:   invokeinterface #52,  1; //InterfaceMethod 
org/jruby/runtime/builtin/IRubyObject.getRuntime:()Lorg/jruby/Ruby;
   7:   dup
   8:   astore_1
   9:   invokevirtual   #56; //Method 
org/jruby/Ruby.getCurrentContext:()Lorg/jruby/runtime/ThreadContext;
   12:  ldc     #57; //String bar
   14:  iconst_0
   15:  anewarray       #49; //class org/jruby/runtime/builtin/IRubyObject
   18:  invokevirtual   #63; //Method 
org/jruby/RubyBasicObject.callMethod:(Lorg/jruby/runtime/ThreadContext;Ljava/lang/String;[Lorg/jruby/runtime/builtin/IRubyObject;)Lorg/jruby/runtime/builtin/IRubyObject;
   21:  ldc     #65; //class java/lang/String
   23:  invokestatic    #71; //Method 
org/jruby/javasupport/JavaUtil.convertRubyToJava:(Lorg/jruby/runtime/builtin/IRubyObject;Ljava/lang/Class;)Ljava/lang/Object;
   26:  areturn
{noformat}

Charlie points out that the Ruby string should be cast to a java.lang.String 
before returning.


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