iterating on a Vector with 4 elements with forEach tag, set begin=2 and end=3, and it yielded the second and third elements instead of the third and fourth. the problem appears to be in the IteratorTagSupport.discard() method. the index variable gets incremented every time through the while loop in this method, but if index == 0, it shouldn't get incremented the first time through (as noted in the IteratorTagSupport.doStartTag() when it calls next() ). (Shawn, thank you very much for all the work you put into this EA1!!!)
Thanks for the bug, Doug. The problem was indeed in discard() but wasn't specifically related to the increment of index, which is just done locally in order to "prime" atEnd(). The problem was that discard() used atEnd() in all cases; atEnd() takes into account 'begin', which is clearly inappropriate until 'begin' is abided by (i.e., in this one particular case). I've fixed by added a discardIgnoreSubset() function. (Note: this part of the implementation could still be cleaned up; I've never really liked this particular strategy and the way that index/count/ getIndex() interact. But I think it's relatively simple and instructive, so I've left it for the moment.)