iteration fails if index var is not used

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: P4
    • 9
    • Affects Version/s: None
    • Component/s: core-libs
    • None
    • b29
    • generic
    • generic

        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)

              Assignee:
              Attila Szegedi
              Reporter:
              Attila Szegedi
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: