Iterators on Clojure's collections should follow the expected JDK behavior of throwing NoSuchElementException on next() when an iterator is exhausted. Current collections have a variety of other behaviors.
Issue encountered in real world code using http://pipes.tinkerpop.com.
This throws a NPE instead of NSEE.
This throws an ArrayIndexOutOfBoundsException instead of NSEE.
An additional problem found during testing is that subvecs will iterate past the subvector end and produce data from the underlying source vector:
Approach: The attached patch fixes the methods by adding a check for hasNext before actually trying to provide the next element. If there is no next element the correct exception is thrown.
|coll||1.8.0-alpha5||-2 patch||-3 patch|
|v||313 us||314 us||306 us|
|sm||723 us||741 us||708 us|
|pv||516 us||546 us||520 us|
Patch: clj-1453-3.patch and tests: CLJ-1453-tests.patch