Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.x
-
None
-
velocity-tools-2.0-beta4 with velocity-1.6.2
Description
$loop.index, $loop.first and other LoopTool methods (that depend on iterator) return null for the last element in a collection.
Try to run:
#set( $list = [1..3] )
#foreach($i in $loop.watch($list))
i[${loop.index}]=$i;
#end
The result is:
i[0]=1; i[1]=2; i[${loop.index}]=3;
I tried to investigate it a little, and seems like the problem is inside "cacheNext(boolean popWhenDone)".
First it checks if (!iterator.hasNext()) and if not then removes this iterator from the stack. But later in this method it retrieves next element from a collection "this.next = iterator.next();". Seems like it causes removing iterator too early, when calling ${loop.index} on the last element the iterator is already removed.
Thanks.