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

Reviving functions in script engine

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Withdrawn
    • Affects Version/s: 6u7
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:

      Description

      E:\alcatel\borsotti\jtest>java -version
      java version "1.6.0_07"
      Java(TM) SE Runtime Environment (build 1.6.0_07-b06)
      Java HotSpot(TM) Client VM (build 10.0-b23, mixed mode, sharing)

      Does this problem occur on J2SE 1.4.x or 5.0.x ? Yes / No (pick one)
      Not known

      Operating System Configuration Information (be specific):
      Windows Vista
      SP1


      Hardware Configuration Information (be specific):
      AMD Athlon X2-64 2Gb RAM


      Bug Description:
      The Rhino scripting engine embedded in Java 6 recreates the "print" and "println" functions each time eva() is called.

      Compile the following program:

      import java.util.*;
      import java.io.*;
      import javax.script.*;

      public class ScriptPrint {
          public static void main(String[] args) throws Exception {

              ScriptEngineManager factory = new ScriptEngineManager();
              ScriptEngine engine = factory.getEngineByName("JavaScript");
              ScriptContext cxt = engine.getContext();
              Bindings bin = cxt.getBindings(ScriptContext.ENGINE_SCOPE);

              System.out.println("scope----first----");
              for (Map.Entry<String,Object> e : bin.entrySet()){
                  System.out.printf("ent: %s %s%n",e,e.getValue().getClass());
              }


              engine.eval("");
              System.out.println("scope----second----");
              for (Map.Entry<String,Object> e : bin.entrySet()){
                  System.out.printf("ent: %s %s%n",e,e.getValue().getClass());

              }

              engine.eval("");
              System.out.println("scope----third----");
              for (Map.Entry<String,Object> e : bin.entrySet()){
                  System.out.printf("ent: %s %s%n",e,e.getValue().getClass());

              }
          }
      }

      Then run it:

      E:\alcatel\borsotti\jtest>java ScriptPrint
      scope----first----
      scope----second----
      ent: println=sun.org.mozilla.javascript.internal.InterpretedFunction@133f1d7 class sun.org.mozilla.javascript.internal.I

      nterpretedFunction
      ent: context=javax.script.SimpleScriptContext@14a9972 class javax.script.SimpleScriptContext
      ent: print=sun.org.mozilla.javascript.internal.InterpretedFunction@a01335 class sun.org.mozilla.javascript.internal.Inte

      rpretedFunction
      scope----third----
      ent: println=sun.org.mozilla.javascript.internal.InterpretedFunction@14d3343 class sun.org.mozilla.javascript.internal.I
      nterpretedFunction
      ent: context=javax.script.SimpleScriptContext@14a9972 class javax.script.SimpleScriptContext

      ent: print=sun.org.mozilla.javascript.internal.InterpretedFunction@1608e05 class sun.org.mozilla.javascript.internal.Int
      erpretedFunction

      Note that the execution of an eval(""), which should produce nothing, makes the

      engine re-create the "print" and "println" functions.
      It does this even when the calling program has deleted them (either with
      bin.remove("print") or with engine.eval("delete print")).

      This means that a script cannot redefine these functions.

      Remedy: refrain from creating these functions in the engine, or make it
      create them only once.

        Attachments

          Activity

            People

            • Assignee:
              sundar Sundararajan Athijegannathan
              Reporter:
              tyao Ting-Yun Ingrid Yao (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: