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

iteration fails if index var is not used

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 9
    • Component/s: core-libs
    • Labels:
      None
    • Subcomponent:
    • Resolved In Build:
      b29
    • CPU:
      generic
    • OS:
      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

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

                  Dates

                  Created:
                  Updated:
                  Resolved: