Forum: JRuby Type mismatch when calling Java method with a class (using .java_class)

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
1f25c17c9d8f45717dab4be5796c0b4f?d=identicon&s=25 Menno Jonkers (Guest)
on 2009-04-22 10:31
(Received via mailing list)
Hi,

While porting some existing Java code to JRuby I'm running into an issue
probably caused by my lack of knowlegde here. If someone could shed some
light on this, that would be most helpful.

I've reduced the problem to a miminal example. I'm running into this
error when running 'jruby test.rb':

  test.rb:6: for method foo expected [#<Java::JavaClass:0x5fBottom line
is that a13338>];
  got: [org.jruby.RubyModule]; error: argument type mismatch (TypeError)

Now test.rb is:

  require 'java'
  require 'test.jar'
  include_class "test.MyTest"

  my_test = MyTest.new
  my_test.foo(Java::MyTest::someValue.java_class)


and test/MyTest.java is:

  package test;

  public class MyTest {

    static String someValue;

    public void foo(java.lang.Class klass) {
    }
  }


and test.jar simply contains test/MyTest.class.

Any hints how I can accomplish passing the Java class?

Thanks,

Menno


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email
1f25c17c9d8f45717dab4be5796c0b4f?d=identicon&s=25 Menno Jonkers (Guest)
on 2009-04-26 19:08
(Received via mailing list)
Hi,

Menno Jonkers wrote:
> [about an argument type mismatch error I'm running into]

I have to decide how to proceed with this port tomorrow and would be
very grateful if someone could give me a pointer on how to move on.

(I've done a fair share of Googling and reading the wiki, but fail to
see where I err...).

Thanks!

Menno


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email
08264fc914cfb45adfea6c2f36f70b21?d=identicon&s=25 Jacob Kessler (Guest)
on 2009-04-27 18:57
(Received via mailing list)
Though I'm much more of a Java programmer than a Ruby programmer, have
you tried calling
my_test.foo(Java::MyTest::someValue.java_class.to_java)? Your issue is
that .java_class is putting out a Ruby module, as you would want for
working with it in Ruby, and the Java VM is a bit picky about its object
types.

Menno Jonkers wrote:
> (I've done a fair share of Googling and reading the wiki, but fail to
>     http://xircles.codehaus.org/manage_email
>
>
>


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email
Ede2aa10c6462f1d825143879be59e38?d=identicon&s=25 Charles Oliver Nutter (Guest)
on 2009-04-27 19:35
(Received via mailing list)
Jacob Kessler wrote:
> Though I'm much more of a Java programmer than a Ruby programmer, have
> you tried calling
> my_test.foo(Java::MyTest::someValue.java_class.to_java)? Your issue is
> that .java_class is putting out a Ruby module, as you would want for
> working with it in Ruby, and the Java VM is a bit picky about its object
> types.

Actually just passing .java_class should work...

âž” jruby -rjava -e "p
java.lang.Compiler.compile_class(org.jruby.RubyString.java_class)"
false

- Charlie

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email
1f25c17c9d8f45717dab4be5796c0b4f?d=identicon&s=25 Menno Jonkers (Guest)
on 2009-04-27 20:18
(Received via mailing list)
Hi Jacob, Charlie,

Charles Oliver Nutter wrote:
> Jacob Kessler wrote:
>> Though I'm much more of a Java programmer than a Ruby programmer, have
>> you tried calling
>> my_test.foo(Java::MyTest::someValue.java_class.to_java)?
>> [...]
> Actually just passing .java_class should work...

That's what I thought, but the call

  my_test.foo(Java::MyTest::someValue.java_class)

still throws the

  test.rb:6: for method foo expected [#<Java::JavaClass:0x5fa13338>];
  got: [org.jruby.RubyModule]; error: argument type mismatch (TypeError)

leaving me puzzled :-/   Any chance that something broken in my
environment/setup causes this?

Cheers,

Menno



----- example code -----

Test.rb is:

  require 'java'
  require 'test.jar'
  include_class "test.MyTest"

  my_test = MyTest.new
  my_test.foo(Java::MyTest::someValue.java_class)

and test/MyTest.java is:

  package test;

  public class MyTest {

    static String someValue;

    public void foo(java.lang.Class klass) {
    }
  }

and test.jar simply contains test/MyTest.class.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email
Ede2aa10c6462f1d825143879be59e38?d=identicon&s=25 Charles Oliver Nutter (Guest)
on 2009-04-27 21:49
(Received via mailing list)
Menno Jonkers wrote:
> That's what I thought, but the call
>
>   my_test.foo(Java::MyTest::someValue.java_class)
>
> still throws the
>
>   test.rb:6: for method foo expected [#<Java::JavaClass:0x5fa13338>];
>   got: [org.jruby.RubyModule]; error: argument type mismatch (TypeError)
>
> leaving me puzzled :-/   Any chance that something broken in my
> environment/setup causes this?

Can you check what that java_class call is actually returning?

This may also be a problem with our logging of dispatch mismatches
that's fixed on master. If you build from master you may get a better
error that says what's actually happening.

- Charlie

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email
1f25c17c9d8f45717dab4be5796c0b4f?d=identicon&s=25 Menno Jonkers (Guest)
on 2009-04-27 22:03
(Received via mailing list)
Charles Oliver Nutter wrote:
> Can you check what that java_class call is actually returning?

  p Java::MyTest::someValue.java_class

returns

  Java::MyTestSomeValueJava_class

Cheers,

Menno


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email
Ede2aa10c6462f1d825143879be59e38?d=identicon&s=25 Charles Oliver Nutter (Guest)
on 2009-04-28 04:25
(Received via mailing list)
Menno Jonkers wrote:
> Charles Oliver Nutter wrote:
>> Can you check what that java_class call is actually returning?
>
>   p Java::MyTest::someValue.java_class
>
> returns
>
>   Java::MyTestSomeValueJava_class

Ahh ok, you're not actually getting the class here...it's trying to turn
your sequence of stuff into one long java package...

Does the class you're trying to pass in actually *work*? I suspect it's
not loading it at all.

- Charlie

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email
1f25c17c9d8f45717dab4be5796c0b4f?d=identicon&s=25 Menno Jonkers (Guest)
on 2009-04-28 22:26
(Received via mailing list)
Charles Oliver Nutter wrote:
> Does the class you're trying to pass in actually *work*? I suspect
> it's not loading it at all.

That simple question seems to have pushed me in the right direction.
Making some progress now. Not able to spend much time on it today and
haven't fully seen the light yet, but things are moving again. Thanks!

Menno

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email
This topic is locked and can not be replied to.