Hi Caleb,
On 23 May 2015 at 16:28:17, Caleb James DeLisle (cjd@cjdns.fr(mailto:cjd@cjdns.fr))
wrote:
Agreed, I can't see what that line should do, if
anything.
The best it can do is add a null element to the list, kicking the value to index 1.
“null” doesn’t exist in velocity AFAIK so the statement is even invalid IMO (see below).
As for the thinking of the author, the comment implies
he didn't clarify his thinking
about what was being done and why so I'd favor simply dropping the line and doing a
few basic (manual) "does it still work" tests to be sure.
No it’s more complex than that, I think the author meant:
#set( $discard = $arr.add( $NULL ) ) ## this may be variable...
If you check the vm the code is:
#set( $discard = $arr.add( null ) ) ## this may be variable...
#set( $discard = $arr.add( "$value" ) )
#set( $discard = $filterMap.put("$key", $arr))
Thus it builds a 2 element list which is then put in a map. This map is passed
to getAllMatchedLocalUsers() (for ex), which says in its javadoc:
* @param matchFields the fields to match. It is a Map with field name as key and for
value :
* <ul>
* <li>"matching string" for document fields</li>
* <li>or ["field type", "matching string"] for
object fields</li>
* </ul>
The javadoc doesn’t mention the support for null as the key. However following the source
code it seems to lead to getAllMatchedLocalUsersOrGroups() which has a more useful
javadoc:
<li>fieldtype : for example StringProperty. If null the field is considered as
document field</li>
Thus it seems the author really wanted to pass null and that would be $NULL.
Ok I’ve checked in a page the result of:
{{velocity}}
#set ($arr = [])
#set( $discard = $arr.add( null ) ) ## this may be variable...
#set( $discard = $arr.add( "value" ) )
$arr
{{/velocity}}
and strangely enough it gives [null, value] :)
So even if invalid it still puts null.
Anyway fixing by using $NULL
Thanks
-Vincent
Thanks,
Caleb
On 05/23/2015 10:56 AM, vincent(a)massol.net wrote:
> Hi devs,
>
> I’ve noticed the following in getusers.vm:
>
> #set ($arr = [])
> #set( $discard = $arr.add( null ) ) ## this may be variable...
> #set( $discard = $arr.add( "$value" ) )
>
>
> The “null” part doesn’t seem correct at all and I don’t understand the comment
"## this may be variable…”
>
> Any idea what the original author wanted to do?
>
> Thanks
> -Vincent
>