commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mark R. Diggory" <mdigg...@latte.harvard.edu>
Subject Re: [JAXL & JELLY] size() behavior question
Date Fri, 28 Feb 2003 18:50:35 GMT
On a related size() note: I've been noticing the following problem.

<?xml version="1.0" encoding="UTF-8"?>
<jelly xmlns="jelly:core">
     <new var="test" className="java.util.ArrayList"/>
     <new var="foo" className="java.lang.String"/>
     ${test.add(foo)}

     <!-- this works -->
     ${size(test)}

     <!-- this doesn't work -->
     <!-- ${test.size()} -->
</jelly>

Seems that ${test.size()} is a legitimate method call on a ListArray 
object like ${test.add(foo)} but doesn't work because size() is being 
reserved for the ${size(test)} function. Couldn't there be a "check" to 
see if the size() method is actually supported by the object before 
rejecting it?

I get the problem:

Feb 28, 2003 1:34:56 PM org.apache.commons.logging.impl.Jdk14Logger error
SEVERE: Caught exception: org.apache.commons.jelly.JellyException: 
null:-1:-1: <
null> Encountered ". size" at line 1, column 5.
Was expecting one of:
     "||" ...
     "or" ...
     "&&" ...
     "and" ...
     "|" ...
     "^" ...
     "&" ...
     "==" ...
     "eq" ...

-Mark Diggory

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.  
> 


---------------------------------------------------------------------
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