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) {
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)