maidh91 / guava-libraries

Automatically exported from code.google.com/p/guava-libraries
Apache License 2.0
0 stars 0 forks source link

Iterators.limit bug #476

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Static method limit in class Iterators should increase the count variable only 
on succesfull iterator.next(); call. Iterator.next() can throw exception.

public T next() {
        if (count >= limitSize) {
          throw new NoSuchElementException();
        }
        T next = iterator.next();
        count++;
        return next;
      }

Original issue reported on code.google.com by vklidu on 11 Nov 2010 at 4:32

GoogleCodeExporter commented 9 years ago
It seems like once an Iterator's next() throws an exception (other than 
NoSuchElementException), its probably dangerous to rely on the Iterator being 
in a consistent state.

Original comment by boppenh...@google.com on 14 Nov 2010 at 8:02

GoogleCodeExporter commented 9 years ago
Agreed; one should not expect sane behavior of any object after it's thrown an 
unchecked exception.  Note that we can't even provide the sane behavior because 
we can't know what state the *backing* iterator is in after this either.

Original comment by kevinb@google.com on 8 Dec 2010 at 3:34

GoogleCodeExporter commented 9 years ago
This issue has been migrated to GitHub.

It can be found at https://github.com/google/guava/issues/<id>

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:15

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 3 Nov 2014 at 9:09