Bug report: iteration on dicts fails if index var is not used

Tal Liron tal.liron at threecrickets.com
Mon Aug 25 04:26:56 UTC 2014


Sorry for using the mailing list, still unclear for me how to open 
Nashorn bugs (the standard form in bugreport.java.com does not have a 
"nashorn" subcategory). The bug is on trunk in 
http://hg.openjdk.java.net/jdk8u/jdk8u-dev/nashorn.

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) {
     print(v[k]+'\n')
     return false
   }
   return true
}

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

x = {test: 'test'}

isEmpty1(x)
isEmpty2(x)



More information about the nashorn-dev mailing list