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

value of global variable does not change when script runs with a new Engine Scope

XMLWordPrintable

      FULL PRODUCT VERSION :
      java version "1.8.0_60"
      java(TM) SE Rutime Environment (build 1.8.0_60-b27)
      java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      import javax.script.ScriptContext;
      import javax.script.ScriptEngine;
      import javax.script.ScriptEngineManager;

      public static void main(String[] args) {
        ScriptEngineManager manager = new ScriptEngineManager();
              
        ScriptEngine engine1 = manager.getEngineByName("nashorn");
        engine1.eval("var sum = 0;");

        // set global variable
        manager.setBindings(engine1.getBindings(ScriptContext.ENGINE_SCOPE));
                
        ScriptEngine engine2 = manager.getEngineByName("nashorn");
        engine2.eval("sum = 150;", engine2.createBindings());
        engine2.eval("print(sum);", engine2.createBindings());
      }

      Expected output: 150
      Actual output: 0

      ------------------------------------------
      run with Java SE 7, output 150.


      REGRESSION. Last worked in version 7u80


      REPRODUCIBILITY :
      This bug can be reproduced always.

            sundar Sundararajan Athijegannathan
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: