commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Geir Magnusson Jr. <ge...@adeptra.com>
Subject Re: [JAXL & JELLY] size() behavior question
Date Tue, 04 Mar 2003 12:55:45 GMT

On Friday, February 28, 2003, at 01:21 PM, Stanley,Michael P. wrote:

> Hi all,
>
> I have question about the current behavior of the size() test (and a
> related question to Jelly).
>
> I was attempting to verify if a property was set.  There are a number 
> of
> ways to do this, but I'm more concerned with the concept than the
> problem.
>
> Usually when checking to see if something is set (like a String or a
> List) you do the following -
>
>          (var == null || var.length() == 0)
>
> This would prevent null pointers, and would also check against the 
> empty
> case.  From my understanding size() was introduced in JEXL to provide a
> common way to detect if it is empty, whether a String or Collection.
>
>          (size(var))
>
> Ok, consider the same null pointer check now ->
>
>          (var == null || size(var))
>
> In this case if var is null this test will through an exception.  I
> think that it should either be consistent with the var == null ||
> var.length() pattern or there should a nullSafeSize() test.
>

or should size() not throw an exception but return something like -1?  
I'm not a fan of such sloppyness, but wouldn't -1 make sense so you 
could test size() > 0 w/o fear?

> -- -- 
Geir Magnusson Jr                                   203-956-2604(w)
Adeptra, Inc.                                       203-247-1713(m)
geirm@adeptra.com


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message