JDK-8055870 : iteration fails if index var is not used
  • Type: Bug
  • Component: core-libs
  • Sub-Component: jdk.nashorn
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2014-08-25
  • Updated: 2015-06-04
  • Resolved: 2014-08-25
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.
8u40Fixed 9 b29Fixed
As reported by Tal Liron at http://mail.openjdk.java.net/pipermail/nashorn-dev/2014-August/003307.html

The following program will cause an exception when "isEmpty2" is called:

 Error: java.lang.ClassCastException: java.lang.String cannot be cast to jdk.nashorn.internal.runtime.Undefined

The only difference between isEmpty1 and isEmpty2 is the actual use of "k". If "k" is not referenced, the exception happens.

function isEmpty1(v) {
 for (var k in v) {
   return false
 return true

function isEmpty2(v) {
 for (var k in v) {
   return false
 return true

x = {test: 'test'}