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

Inconsistent values with JavaImporter after accessing undefined variable

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b29
    • CPU:
      generic
    • OS:
      generic

      Description

      FULL PRODUCT VERSION :
      java version "1.8.0_101"
      Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
      Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      Null value is output when value is not null. The previous value is output instead. Adding whitespace to the expression gives the expected non-null value.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Output should be:
      1
      1

      or ReferenceError should be thrown.
      ACTUAL -
      Output is:
      null
      1

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.script.ScriptEngine;
      import javax.script.ScriptEngineManager;

      public class Main {
      public static void main(String[] args) throws Exception {
      ScriptEngine engine = new ScriptEngineManager().getEngineByName("nashorn");
      engine.eval("with(new JavaImporter(java.util)) { x }");
      engine.eval("with(new JavaImporter(java.util)) { x = 1 }");

      System.out.println(engine.eval("with(new JavaImporter(java.util)) { x }"));
      System.out.println(engine.eval("with(new JavaImporter(java.util)) { x }"));
      }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Disabling class cache in scripting engine produces expected results:

      NashornScriptEngineFactory factory = new NashornScriptEngineFactory();
      ScriptEngine engine = factory.getScriptEngine(new String[] { "--class-cache-size = 0" });

        Attachments

          Activity

            People

            Assignee:
            pmuthuswamy Priya Lakshmi Muthuswamy (Inactive)
            Reporter:
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: