-
Bug
-
Resolution: Fixed
-
P3
-
8
-
b29
-
generic
-
generic
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" });
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" });