[
https://issues.apache.org/jira/browse/VELTOOLS-124?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Sergiy Kovalchuk updated VELTOOLS-124:
--------------------------------------
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.
was:
$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},
#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.
> LoopTool fails to retrieve $loop.index, $loop.first etc for the last element
> in a collection.
> ---------------------------------------------------------------------------------------------
>
> Key: VELTOOLS-124
> URL: https://issues.apache.org/jira/browse/VELTOOLS-124
> Project: Velocity Tools
> Issue Type: Bug
> Components: GenericTools
> Affects Versions: 2.x
> Environment: velocity-tools-2.0-beta4 with velocity-1.6.2
> Reporter: Sergiy Kovalchuk
> Fix For: 2.x
>
>
> $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.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]