Forum: JRuby Can't call JRuby subclass methods after inheriting from Java base class. Confounded. Plz help.

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.
749916b8db96ce30b65e5e2f0397163f?d=identicon&s=25 Ijonas Kisselbach (Guest)
on 2009-02-26 14:14
(Received via mailing list)
Hi,

(using JRuby 1.1.6, JSR-223, and JUnit 4)

I'm trying to get a simple JRuby class inheriting from a Java base
class. For some reason I cannot call the JRuby class' instance methods
when I inherit from the Java base class.

Here's my JRuby code:

require "java"
JDate = java.util.Date
puts JDate.new # this line prints so no classloading issues

class Greetings < JDate
  def say_hello(someones_name)
    message =  "Hi there #{someones_name}"
    javax.swing.JOptionPane.showMessageDialog(nil, message)
  end
end
Greetings.new


---------------------------------------------------------------------------------------------------------
Here's my JUnit test:
  @Test
  public void executeJRubyTask() throws Exception {
    ScriptEngine engine = new
ScriptEngineManager().getEngineByName("jruby");
    Object greetings = engine.eval(rbTaskCode);
    Invocable invocable = (Invocable)engine;
    System.out.println(invocable.invokeMethod(greetings,
"to_s"));                            // this line succeeds printing
current timestamp
    System.out.println(invocable.invokeMethod(greetings, "say_hello",
"Ijonas"));   // this line fails when Greetings < JDate, succeeds when
JDate inherits is removed

  }

Its as if JRuby "masks" the methods when I inherit Greetings from
JDate. Its not a classloading issue because both at the top of the
JRuby script as well as a call to Greetings.to_s, an uptodate date/
timestamp is printed to the console.

Any ideas ? I'm doing something obviously wrong ?


Many thanks,
Ijonas Kisselbach.

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

    http://xircles.codehaus.org/manage_email
Ede2aa10c6462f1d825143879be59e38?d=identicon&s=25 Charles Oliver Nutter (Guest)
on 2009-02-26 21:51
(Received via mailing list)
Ijonas Kisselbach wrote:
> Its as if JRuby "masks" the methods when I inherit Greetings from JDate.
> Its not a classloading issue because both at the top of the JRuby script
> as well as a call to Greetings.to_s, an uptodate date/timestamp is
> printed to the console.
>
> Any ideas ? I'm doing something obviously wrong ?

What you may be seeing is that the object passed out loses its
"rubyness" and so the methods are not available. Can you try to boil
this down into a simple reproducible case and file a bug for it?

- Charlie

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

    http://xircles.codehaus.org/manage_email
749916b8db96ce30b65e5e2f0397163f?d=identicon&s=25 Ijonas Kisselbach (Guest)
on 2009-02-26 23:23
(Received via mailing list)
Thanks Charlie,

The object is definitely losing its "rubyness". I've discovered that
if I pass the proxy object back into the engine using invokeMethod the
rubyness disappears. When I pass it back into the engine via ruby
script function the rubyness is maintained.

I shall knock up a JUnit test case and post it to JRuby JIRA.

Regards,
Ijonas.

On 26 Feb 2009, at 20:50, Charles Oliver Nutter wrote:

>
> - Charlie
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>   http://xircles.codehaus.org/manage_email
>
>


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

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