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

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

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 6
    • Fix Version/s: 6
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b53
    • CPU:
      generic
    • OS:
      generic

      Description

      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.

        Attachments

          Activity

            People

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

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: