JDK-8062381 : String.prototype.charCodeAt called with invalid index throws ClassCastException
  • Type: Bug
  • Component: core-libs
  • Sub-Component: jdk.nashorn
  • Affected Version: 8u40
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2014-10-29
  • Updated: 2015-06-04
  • Resolved: 2014-11-03
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 b39Fixed
Description
When String.prototype.charCodeAt() is called with an invalid index argument it throws a ClassCastException.

jjs> "abc".charCodeAt(10)
java.lang.ClassCastException
java.lang.ClassCastException
	at jdk.nashorn.internal.objects.NativeString.getValidChar(NativeString.java:575)
	at jdk.nashorn.internal.objects.NativeString.charCodeAt(NativeString.java:623)
	at jdk.nashorn.internal.scripts.Script$Recompilation$3$\^shell\_.:program(<shell>:1)
	at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:636)
	at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:229)
	at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:387)
	at jdk.nashorn.internal.runtime.Context.eval(Context.java:697)
	at jdk.nashorn.internal.runtime.Context.eval(Context.java:627)
	at jdk.nashorn.tools.Shell.readEvalPrint(Shell.java:450)
	at jdk.nashorn.tools.Shell.run(Shell.java:158)
	at jdk.nashorn.tools.Shell.main(Shell.java:133)
	at jdk.nashorn.tools.Shell.main(Shell.java:112)

It looks like this is caused by JDK-8025435
http://hg.openjdk.java.net/jdk9/dev/nashorn/rev/f0b5e3900a10
Comments
Assigning to Marcus as he wrote the new charCodeAt code.
31-10-2014