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

Nashorn recursive invocation of eval clobbers bindings

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: 8u45
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:

      Description

      FULL PRODUCT VERSION :
      java version "1.8.0_45"
      Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
      Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      OS X 10.10

      A DESCRIPTION OF THE PROBLEM :
      Test program showing buggy behavior attached below. Basically it looks like a recursive call to eval changes the original bindings part-way through the execution of the enclosing script.



      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package edu;

      import javax.script.*;
      import jdk.nashorn.api.scripting.NashornScriptEngineFactory;

      public class Test {

         static ScriptEngine engine;
         
         public static void main (String[] args) {
            NashornScriptEngineFactory factory = new NashornScriptEngineFactory();
            engine = factory.getScriptEngine(new String[]{"--global-per-engine"});
            Bindings bindings = new SimpleBindings();
            bindings.put("hello", "world");
            try {
               engine.eval("print(hello)", bindings); // prints: world
               // Following prints:
               // nested
               // javax.script.ScriptException: ReferenceError: "hello" is not defined in <eval> at line number 1
               engine.eval("Packages.edu.Test.nested(); print(hello);", bindings);
            } catch (ScriptException e) { System.out.println(e); }
            System.out.println(bindings.get("hello")); // prints: world
         }
         
         public static void nested () {
            try { engine.eval("print('nested')"); } catch (ScriptException e) { System.out.println(e); }
         }
      }
      ---------- END SOURCE ----------

      SUPPORT :
      YES

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: