Forum: JRuby SV: Strange error when calling into jruby1.2 from java using javax.scripting ??

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
M C (Guest)
on 2009-04-15 23:50
(Received via mailing list)
Just found out myself by more testing that the problem is a bug in the
javax.script implementation for JRuby 1.2.The javax.script standard
specifies that to convert a returned object from ScriptEngine.eval to a
java interface, the Invocable.getInterface method should be called.
Unfortunately, this does not work with JRuby, but the
non-scripting-standard feature of converting the returned eval object
directly to the interface, using a normal java type conversion feature,


--- Den lør 11/4/09 skrev M C <removed_email_address@domain.invalid>:

Fra: M C <removed_email_address@domain.invalid>
Emne: [jruby-user] Strange error when calling into jruby1.2 from java
using javax.scripting ??
Til: removed_email_address@domain.invalid
Dato: lørdag 11. april 2009 23.01

I am trying to get jruby1.2 working with the new scripting api on JDK1.6
(JSR 223) but I have run into a strange error with the returned jruby
object not properly implementing a specified java interface. Can anyone
on the list help?

The error I get is an undefined method error as shown below about a
undefined method which is on an interface that the jruby object has been
asked to implement???  As can be shown further below, the jruby code
does implement the interface so it is a bit strange.

First the error that I get:

javax.script.ScriptException: org.jruby.exceptions.RaiseException:
undefined method `clear' for #<Java::JavaObject:0x2b1d8f11>
    at $Proxy14.clear(Unknown Source)

My jruby 1.2 script is as follows:
require 'java'
module Example
  import java.util.Properties # type of config arg
  import com.rv.Service # implementing interface
  import com.rv.Store # type of store arg
  import com.rv.TaskCoordinator # type of coordinaterCallback arg
  class RubyService
      include com.rv.Service
      def restore(store, config, coordinaterCallback)
        puts "Restore
      def clear(config, coordinaterCallback)
        puts "Clear called"


And the java script engine code extract:
ScriptEngine engine = scriptManager.getEngineByName("jruby")
Invocable invocable = (Invocable)engine;
ScriptContext context = engine.getContext();
BufferedReader scriptReader = ...

Object rawResult=engine.eval(scriptReader, context);

com.rv.Service rubyService=invocable.getInterface(rawResult,
rubyService.clear(null, null); # This line fails with the exception
shown above!!

Finally, here is the java interface with the clear method:
package com.rv;
public interface Service
 restore(Store store, Properties config, TaskCoordinator
coordinaterCallback) throws CoreException, InterruptedException,

    void clear(Properties config, TaskCoordinator tc) throws
CoreException, InterruptedException, IOException;

Any idea why this happens?

P.S: The code extracts here are just extracts from a large piece of SW.

Audi, Fiat, Peugeot, Skoda, Porsche, Toyota, Ford - Kelkoo har brugte
biler til en hver smag! Klik  her for at sammenligne priser.

      Trænger du til at se det store billede? Kelkoo giver dig gode
tilbud på LCD TV! Se her
This topic is locked and can not be replied to.