Bug 3732 - iteration begin/discard() bug
Summary: iteration begin/discard() bug
Alias: None
Product: Taglibs
Classification: Unclassified
Component: Standard Taglib (show other bugs)
Version: EA1
Hardware: Sun Solaris
: P3 normal (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
Depends on:
Reported: 2001-09-19 15:50 UTC by Doug Heath
Modified: 2004-11-16 19:05 UTC (History)
0 users


Note You need to log in before you can comment on or make changes to this bug.
Description Doug Heath 2001-09-19 15:50:21 UTC
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!!!)
Comment 1 Shawn Bayern 2001-09-19 20:59:08 UTC
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.)