commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mohan Kishore <mohankish...@yahoo.com>
Subject Re: [Digester] problem calling methods with a primitive parameter
Date Sun, 13 Apr 2003 01:58:30 GMT
One question reg. CallMethodRule: why was the parameters changed from String[]
to Object[]?

I would find the following algo more initutive - any comments:
String p = (String) parameters[i];
if (paramTypes.equals(String.class)) {
    paramValues[i] = p;
} else if (paramTypes[i].isPrimitive()) {
    paramValues[i] = ConvertUtils.convert(p, paramTypes[i]);
} else if (parameters[i] != null) {
    paramValues[i] = ConvertUtils.convert(p, paramTypes[i]);
} else {
    paramValues[i] = null;
}

i.e.
if String no conversion
elseif is primitive value cannot be null, hence convert
else is object, hence convert if not null

btw, the subject line mentioned that the problem is related to a missing
attribute in the XML file. From the code I understand that if the method takes
in a single value from the attribute and that attribute is missing, then the
method never gets called... Am i missing something here?


--- robert burrell donkin <robertburrelldonkin@blueyonder.co.uk> wrote:
> digester 1.4.1 should be backwards compatible with digester 1.3 so i'd say 
> that this sounds like a bug. i'm having trouble replicating the problem 
> exactly and i haven't been able to write a unit test for this case.
> 
> could you give me more details about when the problem occurs including the 
> rules that you are using and details about the parameters that the method 
> takes. ideally, if you could create a simple test case that exhibits this 
> problem with generic classes which you would be willing to donate the the 
> apache software foundation, then so much the better.
> 
> - robert
> 
> On Friday, April 11, 2003, at 10:24 AM, xPosting 02 wrote:
> 
> > hi,
> > I've got a problem as I wanted to update digester 1.3 to 1.4.1 in one of 
> > our
> > projects.
> >
> > I call a method with a primitive (boolean) parameter in a parse rule. if 
> > I
> > don't specify an attribute for this parameter in XML, digster 1.3 
> > converted
> > the null value to false (boolean). digester 1.4.1 doesn't converts the 
> > null
> > value to false (boolean) but tries to call the method with the null value.
> > because the method expects a
> > primitive boolean value java.lang.reflect.Method.invoke(Native Method) 
> > throws
> > a NullPointerException.
> >
> > I think this different behavior between 1.3 and 1.4.1 is because of a
> > difference in CallMethodRule.end()
> >
> >
> > --- digester 1.4.1 ---
> > // Construct the parameter values array we will need
> > // We only do the conversion if the param value is a String and
> > // the specified paramType is not String.
> > Object paramValues[] = new Object[paramTypes.length];
> > for (int i = 0; i < paramTypes.length; i++) {
> >     if(parameters[i] instanceof String &&
> >        !String.class.isAssignableFrom(paramTypes[i])) {
> >
> >         paramValues[i] =
> >                 ConvertUtils.convert((String) parameters[i], paramTypes[i]
> > );
> >     } else {
> >         paramValues[i] = parameters[i];
> >     }
> > }
> > --- ---
> >
> > --- digester 1.3 ---
> > // Construct the parameter values array we will need
> > Object paramValues[] = new Object[paramTypes.length];
> > for (int i = 0; i < paramTypes.length; i++) {
> >     paramValues[i] =
> >             ConvertUtils.convert(parameters[i], paramTypes[i]);
> > }
> > --- ---
> >
> > is this behavior in 1.4.1 a bug or is it 'by design'.
> > if 'by design' is there another solution than writing a method which 
> > expects
> > a java.lang.Boolean parameter?
> >
> > joel
> >
> >
> > --------------------------------------------
> > MySign AG, Switzerland
> > Web: http://www.mysign.ch
> > --------------------------------------------
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: commons-dev-help@jakarta.apache.org
> >
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
> 


__________________________________________________
Do you Yahoo!?
Yahoo! Tax Center - File online, calculators, forms, and more
http://tax.yahoo.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