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


#1

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

#2

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

#3

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