Issue1544224

classification
Title: unable to iterate twice on the same collection
Type: Severity: normal
Components: Core Versions:
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: cgroves, fgagnon2
Priority: normal Keywords:

Created on 2006-08-21.21:16:38 by fgagnon2, last changed 2006-08-22.02:29:07 by cgroves.

Messages
msg1209 (view) Author: Francois Gagnon (fgagnon2) Date: 2006-08-21.21:16:38
Given a collection, I am unable to iterate twice on the
same collection.  


atom 17:03:36 ~> jython
Jython 2.1 on java1.5.0_07 (JIT: null)
Type "copyright", "credits" or "license" for more
information.
>>> from java.util import HashSet
>>> set = HashSet()
>>> set.add(1)
1
>>> for i in set:
...   print i
... 
1
>>> for u in set:
...   print u
... 
Traceback (innermost last):
  File "<console>", line 1, in ?
ValueError: iterator indices must be consecutive ints
starting at 0
msg1210 (view) Author: Francois Gagnon (fgagnon2) Date: 2006-08-21.21:32:05
Logged In: YES 
user_id=1580846

Clearly, the iterator returned for the 'for' loop is never
resetted where it should be.  One can force a new iterator
to be created by using the following (unelegant) work around:

atom 17:30:00 ~> jython
fJython 2.1 on java1.5.0_07 (JIT: null)
Type "copyright", "credits" or "license" for more information.
>>>from java.util import HashSet
>>> set = HashSet()
>>> set.add(1)
1
>>> for i in set.iterator():
...    print i
... 
1
>>> for u in set.iterator():
...    print u
... 
1
msg1211 (view) Author: Charlie Groves (cgroves) Date: 2006-08-22.02:29:07
Logged In: YES 
user_id=1174327

Thanks for the report.  It looks like this is already fixed
in 2.2a1 and onwards.  I'm glad you found a workaround for
2.1, inelegant though it may be.
History
Date User Action Args
2006-08-21 21:16:38fgagnon2create