JDK-8077955 : Undeclared globals in eval code should not be handled as fast scope
  • Type: Bug
  • Component: core-libs
  • Sub-Component: jdk.nashorn
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2015-04-16
  • Updated: 2015-09-29
  • Resolved: 2015-04-16
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8 JDK 9
8u60Fixed 9 b61Fixed
Description
Undeclared globals in eval code can refer to anything in the containing environment, so even if they qualify for the fast-scope flag within the eval script, the callsite should not be handled as fast scope when linking with a property of the containing environment. 

This bug can be replicated by running the test case from JDK-8026167 with objects fields:

jjs -Dnashorn.fields.objects test/script/basic/JDK-8026167.js
Exception in thread "main" java.lang.ClassCastException: Cannot cast jdk.nashorn.internal.scripts.JO2P0 to jdk.nashorn.internal.scripts.JO1P1
	at java.lang.invoke.MethodHandleImpl.newClassCastException(MethodHandleImpl.java:361)
	at java.lang.invoke.MethodHandleImpl.castReference(MethodHandleImpl.java:356)
	at jdk.nashorn.internal.scripts.Script$Recompilation$8$\^eval\_#1\!27\^eval\_.:program(<eval>#1:27<eval>:1)
	at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:636)
	at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:228)
	at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:393)
	at jdk.nashorn.internal.runtime.Context.eval(Context.java:712)
	at jdk.nashorn.internal.objects.Global.directEval(Global.java:1250)