Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8055870

iteration fails if index var is not used

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • 9
    • None
    • core-libs
    • None
    • b29
    • generic
    • generic

    Backports

      Description

        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)

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                  Created:
                  Updated:
                  Resolved: