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

(coll) Map entrySet iterators should return different entries on each call to next()

XMLWordPrintable

    • 5.0
    • b140
    • generic, x86
    • generic, windows_xp
    • Verified

      Some Map implementations have an entrySet() method returning a set
      with an iterator method returning an iterator which returns the
      same (as in object identity) Map.Entry on each call to next().
      This works well in the usual case where each entry is discarded
      (effectively becomes garbage) before next() is called.
      However, if entries are saved, perhaps to build up other collections or
      arrays, they will need to be defensively copied by the caller before next()
      is called. This is an optimization to prevent garbage being generated on each
      call to next(). However, the cost of creating many small short-lived objects is much
      lower than it used to be in most implementations, and is likely to get even lower as VM
      optimizations such as escape analysis and stack allocation are implemented.
      Therefore such error-prone optimizations such as this one should be removed at
      some point.

            mduigou Mike Duigou
            martin Martin Buchholz
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: