JDK-8058179 : Global constants get in the way of self-modifying properties
  • Type: Bug
  • Component: core-libs
  • Sub-Component: jdk.nashorn
  • Affected Version: 8u20
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2014-09-10
  • Updated: 2015-06-04
  • Resolved: 2014-09-11
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
8u40Fixed 9 b31Fixed
Description
The avatar.js test test-repl.js throws this exception with 8u40 - "java.lang.ClassCastException: jdk.nashorn.internal.scripts.JO4 cannot be cast to jdk.nashorn.internal.runtime.UserAccessorProperty$Accessors".

This error does not occur with 8u20. It also occurs with 8u40 with optimistic types turned off.

The error happens here -

sending "url.format(\"http://google.com\")"
Unix data: "java.lang.ClassCastException: jdk.nashorn.internal.scripts.JO4 cannot be cast to jdk.nashorn.internal.runtime.UserAccessorProperty$Accessors\nnode via Unix socket> ", expecting "http://google.com/"

This error can also be reproduced running the REPL manually -

java -Dnashorn.args='--optimistic-types=false' -jar dist/avatar-js.jar
> url.format("http://google.com")
java.lang.ClassCastException: jdk.nashorn.internal.scripts.JO4 cannot be cast to jdk.nashorn.internal.runtime.UserAccessorProperty$Accessors

But a simple test case works fine -

cat format.js
print(require('url').format("http://google.com"));

java -Dnashorn.args='--optimistic-types=false' -jar dist/avatar-js.jar format.js
http://google.com/

Something in url.format does not work with 8u40 when called by a REPL.

Comments
The problem is with GlobalConstants evaluating the property during the execution of ScriptObject.findGetMethod. In the case of a self modifying getter/setter based property this causes the looked up property to become invalid. I changed the bug title to reflect this.
11-09-2014