velocity-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sergiy Kovalchuk (JIRA)" <>
Subject [jira] Commented: (VELOCITY-692) have #if handle empty strings/arrays/collections/maps more conveniently
Date Fri, 13 Feb 2009 16:54:59 GMT


Sergiy Kovalchuk commented on VELOCITY-692:

I think it is pretty unexpected for a user. It basically means that you are not allowed to
use length() or isEmpty() methods in your objects for your needs. If I have length or empty
fields returning false or null or " ", it doesn't necessary mean that the whole object should
be treated as null or empty. Plus "length" and "empty" are pretty common names, nobody expects
that they will become reserved one day for checking if the whole object is empty. Lets say
I have Rectangle object with "height" and "length" fields, or Train object with isEmpty method,
it doesn't mean that rectangle with length not set or train that is not loaded are equal to
null (maybe not the best examples, but you got the idea)

Even returning false if obj.toString()==null (not to mention length==0) caught me by surprise.
I never thought that it is doing this check until saw it in the code. What if I have toString
method returning only one field of an object that can be null or ""? I would spend a lot of
time trying to figure out why does this object is treated as null in #if statements. At least
such behavior should be noted in documentation with big red letters, because it is pretty
unexpected I think. toString() should be used however you want and nobody else should rely
on it in my opinion.

I think much safer would be just to check specifically CharSequence, Collection, Map, array
(anything else?) for their length/size.

> have #if handle empty strings/arrays/collections/maps more conveniently
> -----------------------------------------------------------------------
>                 Key: VELOCITY-692
>                 URL:
>             Project: Velocity
>          Issue Type: New Feature
>          Components: Engine
>            Reporter: Nathan Bubna
>            Priority: Trivial
> An idea from the dev list:
> -------------------------------------------------------------------------------------------------
> On Sat, Feb 7, 2009 at 3:41 PM,  <> wrote:
> > Hello,
> > I wanted to share with you a few ideas I have about new simple
> > improvements for DisplayTools. I should be able to make patches for
> > them if you are interested.
> >
> > 1. Add new method
> >
> > isEmpty(object)
> >
> > that will return true if the object is null or empty (for strings it's
> > zero length; for collections, maps and arrays it's zero size). This
> > should help with  annoying null checks. (Probably a better place for
> > this method would be Engine, not Tools)
> yeah, not something for tools.  would be interesting to have the
> Uberspect pretend that every non-null reference has an isEmpty()
> method, or perhaps just add 0-length strings, empty collections, empty
> maps and 0-length arrays to the list of things that #if( $foo )
> considers false.
> -------------------------------------------------------------------------------------------------

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:
For additional commands, e-mail:

View raw message