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

javascript engine can not write to StringWriter.

    Details

    • Subcomponent:
    • Resolved In Build:
      b128
    • CPU:
      generic
    • OS:
      generic
    • Verification:
      Verified

      Description

      The following example throws stack trace:


      import javax.script.ScriptContext;
      import javax.script.ScriptEngine;
      import javax.script.ScriptEngineManager;

      import java.io.StringWriter;


      class ScriptTestJs
      {
       public static void main(String[] args)
       {
       
         ScriptEngineManager sem = new ScriptEngineManager();
         ScriptEngine jsengine = sem.getEngineByName("javascript");

         StringWriter sw = new StringWriter();
       
         try
         {
           jsengine.eval("print(\"hello world 1\\n\")");
           jsengine.getContext().setWriter(sw);
           jsengine.eval("print(\"hello world 2\\n\")");
         }
         catch(Throwable e)
         {
           e.printStackTrace();
         }
       }
      };

      java ScriptTestJs
      hello world 1
      javax.script.ScriptException: sun.org.mozilla.javascript.internal.EcmaError: TypeError: Cannot find function print. (print#8) in print at line number 8
      at com.sun.script.javascript.RhinoScriptEngine.eval(Unknown Source)
      at com.sun.script.javascript.RhinoScriptEngine.eval(Unknown Source)
      at javax.script.AbstractScriptEngine.eval(Unknown Source)
      at ScriptTestJs.main(ScriptTestJs.java:26)

        Attachments

          Activity

            People

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

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: