Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6320169

arguments passed to javax.script.Invocable.invoke are not converted to script wrappers

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 6
    • 6
    • core-libs
    • b53
    • generic
    • generic

      In the following test, a JavaScript function is called from Java program.

      import javax.script.*;

      public class Test {
          public static void main(String[] argv) throws Exception {
              ScriptEngineManager manager = new ScriptEngineManager();
              ScriptEngine engine = manager.getEngineByName("js");

              // function expects a java.io.File object.
              engine.eval(
                 "function func(obj) { " +
                 " if (!(obj instanceof java.io.File)) { " +
                 " throw 'file expected'; " +
                 " } else { " +
                 " print('got : ' + obj); " +
                 " } " +
                 "} ");

              Invocable in = (Invocable) engine;
              // call the func by passing a java.io.File object
              // we don't expect exception because we are passing right
              // type of object as argument...
              in.invoke("func", new Object[] { new java.io.File(".") });
          }
      }


      We don't expect any exception in the above program. But, we get exception with the following trace:

      Exception in thread "main" javax.script.ScriptException: sun.org.mozilla.javascript.internal.JavaScriptException: file expected (<Unknown source>#1) in <Unknown source> at line number 1
              at com.sun.script.javascript.RhinoScriptEngine.invoke(RhinoScriptEngine.java:204)
              at com.sun.script.javascript.RhinoScriptEngine.invoke(RhinoScriptEngine.java:156)
              at Test.main(Test.java:20)

      It seems that the arguments passed to script function are not converted to correct script wrapper objects.

            sundar Sundararajan Athijegannathan
            sundar Sundararajan Athijegannathan
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: