[xwiki-users] $xwiki not always available?
Thomas Drevon
thomas.drevon at intermedia.uio.no
Mon Jul 30 10:51:41 CEST 2007
Erin Schnabel wrote:
>
> I've seen a few of these, and it doesn't really have anything to do
> with the $xwiki reference (though perhaps the code should be changed
> to avoid that misleading message..). The original cause is an NPE
> originating out of Collections.sort, which is called by XWiki.sort:
>
> XWiki.sort:
>
> public List sort(List list)
> {
> Collections.sort(list);
> return list;
> }
>
> Collections.sort doesn't appear to check for null:
>
> public static <T extends Comparable<? super T>> void sort(List<T> list) {
> Object[] a = list.toArray();
> Arrays.sort(a);
>
> Seems to me like your panel needs to make sure your list is non-null
> (not empty) before calling xwiki.sort
Thanks for taking the time to answer me! I see the flaw that you
pointing out.
> The recommended (from the velocity docs) way to check for non-null && not empty:
>
> #if( "$!allTags" != '')
> #set( $allTagsSorted = $xwiki.sort($allTags))
> #end
>
> That should solve the problem.
I ended up doing something similar:
#set( $allTags = $xwiki.search($query))
#if ( $allTags.size() > 1)
...do stuff
#end
However, I'm absolutely positive that my list of tags isn't empty, so
this can't the ultimate cause of the problem. This was confirmed by
Sergiu Dumitriu; he recently updated the jira issue concerning the
inclusion of the above mentioned tag cloud in xwiki. Check it out:
http://jira.xwiki.org/jira/browse/XE-51
cheers :-)
Thomaas
More information about the users
mailing list