You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by xPosting 02 <po...@mysign.ch> on 2003/04/11 11:24:38 UTC

[Digester] problem calling methods with a primitive parameter but no xml attribute specified

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


Re: [Digester] problem calling methods with a primitive parameter but no xml attribute specified

Posted by Micael <ca...@harbornet.com>.
Boy, Sis,

You were up late.  Let me know about these things before hand and then I 
can tell you how much I love you and how well I hope things go.  I know 
that won't change anything, but it will give you another person sitting in 
your corner in your head and heart.  You don't have to do these things 
alone.  That is why you have older and younger brothers.  I am glad that 
things went well.  You must have been really scared.  We are pretty 
vulnerable as people.  Seems like everyone is having their share of things 
this last couple months.

Love,

Michael

At 10:26 AM 4/12/03 +0100, you 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
>



LEGAL NOTICE

This electronic mail  transmission and any accompanying documents contain 
information belonging to the sender which may be confidential and legally 
privileged.  This information is intended only for the use of the 
individual or entity to whom this electronic mail transmission was sent as 
indicated above. If you are not the intended recipient, any disclosure, 
copying, distribution, or action taken in reliance on the contents of the 
information contained in this transmission is strictly prohibited.  If you 
have received this transmission in error, please delete the message.  Thank 
you  



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


Re: [Digester] problem calling methods with a primitive parameter but no xml attribute specified

Posted by robert burrell donkin <ro...@blueyonder.co.uk>.
hi joel

the logs have given me a good start but what would be very useful is an 
idea of the calls which are made to set up the rules.

for example,

	...
	digester.setNextRule("blah", "path")
	...

this would allow me to narrow down the possibilities. if you're not happy 
about posting this information to a public forum, then email me directly 
and/or sanitize the names. for example,

	digester.setNextRule("secretMethod", "confidential/path") -> 
digester.setNextRule("aMethod", "alpha/beta")

- robert

On Wednesday, April 16, 2003, at 11:28 AM, Joel Gautschi wrote:

> hi robert,
> i wasn't able to test your bugfix because it looks like there is another 
> problem with commons-digester-src-20030416.zip / CVS version. the problem 
> doesn't occure if i use digester 1.3.
>
> i attach a part of the log to his mail. if you need further information,  
> just mail me.
>
> thanks for your help and that you take backward compatibility seriously!
>
> joel
>
>
> robert burrell donkin wrote:
>> thanks Joel, i've been able to construct a test case and a (i think) a 
>> fix.
>> could you please test your code against CVS HEAD or wait until the next 
>> nightly build and then post back the results to the list?
>> we take backwards compatibility seriously and if this problem has been 
>> fixed i intend to push for a new digester release.
>> TIA
>> - robert
>> On Monday, April 14, 2003, at 09:36 AM, Joel Gautschi wrote:
>>> hi robert,
>>>
>>> I wrote three classes and an xml file to demonstrate the problem.
>>>
>>> digester 1.4.1 throws a java.lang.NullPointerException
>>> digester 1.3 returns: stringValue: 'test string' booleanValue: 'false'
>>>
>>> if I add the xml attribute booleanValue with a value to <document> in 
>>> test.xml (like <document stringValue="test string" 
>>> booleanValue="true">) digester 1.4.1 and 1.3 work both.
>>>
>>> hope the classes help.
>>> thanks for your time!
>>> joel
>>>
>>> robert burrell donkin 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
>>>
>>> <document stringValue="test string">
>>> </document>package test;
>>>
>>> public class TestUtils
>>> {
>>>     public void printTestValues( String stringValue, boolean 
>>> booleanValue )
>>>     {
>>>         System.out.println( "stringValue: '" + stringValue +
>>>                             "' booleanValue: '" + booleanValue + "'" );
>>>     }
>>> }package test;
>>>
>>> import org.apache.commons.digester.Digester;
>>> import org.apache.commons.digester.RuleSetBase;
>>>
>>> public class TestParseRules extends RuleSetBase
>>> {
>>>     public void addRuleInstances(Digester digester)
>>>     {
>>>         digester.addCallMethod( "document",
>>>             "printTestValues", 2, new Class[] { String.class, 
>>> boolean.class } );
>>>         digester.addCallParam( "document",
>>>             0, "stringValue" );
>>>         digester.addCallParam( "document",
>>>             1, "booleanValue" );
>>>     }
>>> }package test;
>>>
>>> import java.io.File;
>>>
>>> import org.apache.commons.digester.Digester;
>>>
>>> public class Test
>>> {
>>>     public static void main(String[] args)
>>>     {
>>>         Digester digester = new Digester();
>>>         digester.addRuleSet( new TestParseRules() );
>>>         digester.push ( new TestUtils() );
>>>         try
>>>         {
>>>             digester.parse( new File ( "test.xml" )  );
>>>         }
>>>         catch ( org.xml.sax.SAXException e )
>>>         {
>>>             e.printStackTrace();
>>>         }
>>>         catch ( java.io.IOException e )
>>>         {
>>>             e.printStackTrace();
>>>         }
>>>     }
>>> }
>>> ---------------------------------------------------------------------
>>> 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
> .
> .
> .
> 2003-04-16 12:19:43,812 DEBUG org.apache.commons.digester.Digester -   
> New match='inputconfig/database/dbfields/dbfield/validator/param'
> 2003-04-16 12:19:43,812 DEBUG org.apache.commons.digester.Digester -   
> Fire begin() for 
> ObjectCreateRule[className=ch.mysign.cms.commons.CustomParameter, 
> attributeName=null]
> 2003-04-16 12:19:43,812 DEBUG org.apache.commons.digester.Digester - 
> [ObjectCreateRule]{inputconfig/database/dbfields/dbfield/validator/param}
> New ch.mysign.cms.commons.CustomParameter
> 2003-04-16 12:19:43,812 DEBUG org.apache.commons.digester.Digester -   
> Fire begin() for SetNextRule[methodName=addParam, paramType=ch.mysign.cms.
> commons.CustomParameter]
> 2003-04-16 12:19:43,812 DEBUG org.apache.commons.digester.Digester -   
> Fire begin() for CallMethodRule[methodName=setTypeAndValue, paramCount=2,
>  paramTypes={java.lang.String, java.lang.String}]
> 2003-04-16 12:19:43,822 DEBUG org.apache.commons.digester.Digester - 
> Pushing params
> 2003-04-16 12:19:43,822 DEBUG org.apache.commons.digester.Digester -   
> Fire begin() for CallParamRule[paramIndex=0, attributeName=class, from 
> stack=false]
> 2003-04-16 12:19:43,822 DEBUG org.apache.commons.digester.Digester -   
> Fire begin() for CallParamRule[paramIndex=1, attributeName=null, from 
> stack=false]
> 2003-04-16 12:19:43,822 DEBUG org.apache.commons.digester.Digester -   
> Fire begin() for CallMethodRule[methodName=setEvaluate, paramCount=1, 
> paramTypes={boolean}]
> 2003-04-16 12:19:43,822 DEBUG org.apache.commons.digester.Digester - 
> Pushing params
> 2003-04-16 12:19:43,822 DEBUG org.apache.commons.digester.Digester -   
> Fire begin() for CallParamRule[paramIndex=0, attributeName=evaluate, from 
> stack=false]
> 2003-04-16 12:19:43,822 DEBUG org.apache.commons.digester.Digester.sax - 
> characters(50)
> 2003-04-16 12:19:43,822 DEBUG org.apache.commons.digester.Digester.sax - 
> endElement(,,param)
> 2003-04-16 12:19:43,822 DEBUG org.apache.commons.digester.Digester -   
> match='inputconfig/database/dbfields/dbfield/validator/param'
> 2003-04-16 12:19:43,822 DEBUG org.apache.commons.digester.Digester -   
> bodyText='50'
> 2003-04-16 12:19:43,822 DEBUG org.apache.commons.digester.Digester -   
> Fire body() for 
> ObjectCreateRule[className=ch.mysign.cms.commons.CustomParameter, 
> attributeName=null]
> 2003-04-16 12:19:43,822 DEBUG org.apache.commons.digester.Digester -   
> Fire body() for SetNextRule[methodName=addParam, paramType=ch.mysign.cms.
> commons.CustomParameter]
> 2003-04-16 12:19:43,822 DEBUG org.apache.commons.digester.Digester -   
> Fire body() for CallMethodRule[methodName=setTypeAndValue, paramCount=2, 
> paramTypes={java.lang.String, java.lang.String}]
> 2003-04-16 12:19:43,822 DEBUG org.apache.commons.digester.Digester -   
> Fire body() for CallParamRule[paramIndex=0, attributeName=class, from 
> stack=false]
> 2003-04-16 12:19:56,921 DEBUG org.apache.commons.digester.Digester -   
> Fire body() for CallParamRule[paramIndex=1, attributeName=null, from 
> stack=false]
> 2003-04-16 12:19:56,931 ERROR org.apache.commons.digester.Digester - Body 
> event threw exception
> java.lang.ArrayIndexOutOfBoundsException
> 	at 
> org.apache.commons.digester.CallParamRule.body(CallParamRule.java:266)
> 	at org.apache.commons.digester.Rule.body(Rule.java:240)
> 	at org.apache.commons.digester.Digester.endElement(Digester.java:1034)
> 	at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown 
> Source)
> 	at org.apache.xerces.impl.XMLNamespaceBinder.endElement(Unknown 
> Source)
> 	at 
> org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanEndElement
> (Unknown Source)
> 	at 
> org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.
> dispatch(Unknown Source)
> 	at 
> org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument
> (Unknown Source)
> 	at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
> 	at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
> 	at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
> 	at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
> 	at org.apache.commons.digester.Digester.parse(Digester.java:1538)
> .
> .
> .
> .
> ---------------------------------------------------------------------
> 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


Re: [Digester] problem calling methods with a primitive parameter but no xml attribute specified

Posted by Joel Gautschi <jo...@gameoefter.org>.
hi robert,
i wasn't able to test your bugfix because it looks like there is another 
problem with commons-digester-src-20030416.zip / CVS version. the 
problem doesn't occure if i use digester 1.3.

i attach a part of the log to his mail. if you need further information, 
  just mail me.

thanks for your help and that you take backward compatibility seriously!

joel


robert burrell donkin wrote:
> thanks Joel, i've been able to construct a test case and a (i think) a fix.
> 
> could you please test your code against CVS HEAD or wait until the next 
> nightly build and then post back the results to the list?
> 
> we take backwards compatibility seriously and if this problem has been 
> fixed i intend to push for a new digester release.
> 
> TIA
> 
> - robert
> 
> On Monday, April 14, 2003, at 09:36 AM, Joel Gautschi wrote:
> 
>> hi robert,
>>
>> I wrote three classes and an xml file to demonstrate the problem.
>>
>> digester 1.4.1 throws a java.lang.NullPointerException
>> digester 1.3 returns: stringValue: 'test string' booleanValue: 'false'
>>
>> if I add the xml attribute booleanValue with a value to <document> in 
>> test.xml (like <document stringValue="test string" 
>> booleanValue="true">) digester 1.4.1 and 1.3 work both.
>>
>> hope the classes help.
>> thanks for your time!
>> joel
>>
>> robert burrell donkin 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
>>
>> <document stringValue="test string">
>> </document>package test;
>>
>> public class TestUtils
>> {
>>     public void printTestValues( String stringValue, boolean 
>> booleanValue )
>>     {
>>         System.out.println( "stringValue: '" + stringValue +
>>                             "' booleanValue: '" + booleanValue + "'" );
>>     }
>> }package test;
>>
>> import org.apache.commons.digester.Digester;
>> import org.apache.commons.digester.RuleSetBase;
>>
>> public class TestParseRules extends RuleSetBase
>> {
>>     public void addRuleInstances(Digester digester)
>>     {
>>         digester.addCallMethod( "document",
>>             "printTestValues", 2, new Class[] { String.class, 
>> boolean.class } );
>>         digester.addCallParam( "document",
>>             0, "stringValue" );
>>         digester.addCallParam( "document",
>>             1, "booleanValue" );
>>     }
>> }package test;
>>
>> import java.io.File;
>>
>> import org.apache.commons.digester.Digester;
>>
>> public class Test
>> {
>>     public static void main(String[] args)
>>     {
>>         Digester digester = new Digester();
>>         digester.addRuleSet( new TestParseRules() );
>>         digester.push ( new TestUtils() );
>>         try
>>         {
>>             digester.parse( new File ( "test.xml" )  );
>>         }
>>         catch ( org.xml.sax.SAXException e )
>>         {
>>             e.printStackTrace();
>>         }
>>         catch ( java.io.IOException e )
>>         {
>>             e.printStackTrace();
>>         }
>>     }
>> }
>> ---------------------------------------------------------------------
>> 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
> 
> 
> 

Re: [Digester] problem calling methods with a primitive parameter but no xml attribute specified

Posted by robert burrell donkin <ro...@blueyonder.co.uk>.
thanks Joel, i've been able to construct a test case and a (i think) a fix.

could you please test your code against CVS HEAD or wait until the next 
nightly build and then post back the results to the list?

we take backwards compatibility seriously and if this problem has been 
fixed i intend to push for a new digester release.

TIA

- robert

On Monday, April 14, 2003, at 09:36 AM, Joel Gautschi wrote:

> hi robert,
>
> I wrote three classes and an xml file to demonstrate the problem.
>
> digester 1.4.1 throws a java.lang.NullPointerException
> digester 1.3 returns: stringValue: 'test string' booleanValue: 'false'
>
> if I add the xml attribute booleanValue with a value to <document> in 
> test.xml (like <document stringValue="test string" booleanValue="true">) 
> digester 1.4.1 and 1.3 work both.
>
> hope the classes help.
> thanks for your time!
> joel
>
> robert burrell donkin 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
> <document stringValue="test string">
> </document>package test;
>
> public class TestUtils
> {
>     public void printTestValues( String stringValue, boolean booleanValue 
> )
>     {
>         System.out.println( "stringValue: '" + stringValue +
>                             "' booleanValue: '" + booleanValue + "'" );
>     }
> }package test;
>
> import org.apache.commons.digester.Digester;
> import org.apache.commons.digester.RuleSetBase;
>
> public class TestParseRules extends RuleSetBase
> {
>     public void addRuleInstances(Digester digester)
>     {
>         digester.addCallMethod( "document",
>             "printTestValues", 2, new Class[] { String.class, 
> boolean.class } );
>         digester.addCallParam( "document",
>             0, "stringValue" );
>         digester.addCallParam( "document",
>             1, "booleanValue" );
>     }
> }package test;
>
> import java.io.File;
>
> import org.apache.commons.digester.Digester;
>
> public class Test
> {
>     public static void main(String[] args)
>     {
>         Digester digester = new Digester();
>         digester.addRuleSet( new TestParseRules() );
>         digester.push ( new TestUtils() );
>         try
>         {
>             digester.parse( new File ( "test.xml" )  );
>         }
>         catch ( org.xml.sax.SAXException e )
>         {
>             e.printStackTrace();
>         }
>         catch ( java.io.IOException e )
>         {
>             e.printStackTrace();
>         }
>     }
> }
> ---------------------------------------------------------------------
> 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


Re: [Digester] problem calling methods with a primitive parameter but no xml attribute specified

Posted by Joel Gautschi <jo...@gameoefter.org>.
hi robert,

I wrote three classes and an xml file to demonstrate the problem.

digester 1.4.1 throws a java.lang.NullPointerException
digester 1.3 returns: stringValue: 'test string' booleanValue: 'false'

if I add the xml attribute booleanValue with a value to <document> in 
test.xml (like <document stringValue="test string" booleanValue="true">) 
digester 1.4.1 and 1.3 work both.

hope the classes help.
thanks for your time!
joel

robert burrell donkin 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
> 
> 
> 

Re: [Digester] problem calling methods with a primitive parameter

Posted by robert burrell donkin <ro...@blueyonder.co.uk>.
On Sunday, April 13, 2003, at 08:41 PM, Mohan Kishore wrote:

> --- robert burrell donkin <ro...@blueyonder.co.uk> wrote:
>>> I would find the following algo more initutive - any comments:
>>> String p = (String) parameters[i];
>>> if (paramTypes[i].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'm now thinking along the lines that maybe all nulls and any objects
>> which are not compatible with the given parameter type should be 
>> converted.
>
> how about the case when the user wants the missing parameters to be 
> passed in
> as nulls? We need to ensure that missing primitives are converted to their
> default values. I guess what I am saying is that the wrapper converters 
> should
> have a default value, and all other converters should return null when 
> null is
> being converted...

should have consulted the javadocs before opening my mouth :)

ConvertUtils only takes strings so an additional test that makes sure 
nulls are tested is the right fix.

- robert


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


Re: [Digester] problem calling methods with a primitive parameter

Posted by robert burrell donkin <ro...@blueyonder.co.uk>.
On Sunday, April 13, 2003, at 08:41 PM, Mohan Kishore wrote:

> --- robert burrell donkin <ro...@blueyonder.co.uk> wrote:
>>> I would find the following algo more initutive - any comments:
>>> String p = (String) parameters[i];
>>> if (paramTypes[i].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'm now thinking along the lines that maybe all nulls and any objects
>> which are not compatible with the given parameter type should be 
>> converted.
>
> how about the case when the user wants the missing parameters to be 
> passed in
> as nulls? We need to ensure that missing primitives are converted to their
> default values. I guess what I am saying is that the wrapper converters 
> should
> have a default value, and all other converters should return null when 
> null is
> being converted...

this is the advantage of using ConvertUtils. the standard converters 
behave very reasonably (pretty much the way you're describing) and if this 
behaviour isn't what's wanted then the user can register custom converter 
which work in the way they want.

once the beanification work on BeanUtils has been finished, i'd probably 
like to add get/set properties for BeanUtilsBean on digester. this will 
allow more finely grained over conversions.

- robert


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


Re: [Digester] problem calling methods with a primitive parameter

Posted by Mohan Kishore <mo...@yahoo.com>.
--- robert burrell donkin <ro...@blueyonder.co.uk> wrote:
> > I would find the following algo more initutive - any comments:
> > String p = (String) parameters[i];
> > if (paramTypes[i].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'm now thinking along the lines that maybe all nulls and any objects 
> which are not compatible with the given parameter type should be converted.

how about the case when the user wants the missing parameters to be passed in
as nulls? We need to ensure that missing primitives are converted to their
default values. I guess what I am saying is that the wrapper converters should
have a default value, and all other converters should return null when null is
being converted...

__________________________________________________
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


Re: [Digester] problem calling methods with a primitive parameter

Posted by robert burrell donkin <ro...@blueyonder.co.uk>.
On Sunday, April 13, 2003, at 02:58 AM, Mohan Kishore wrote:

> One question reg. CallMethodRule: why was the parameters changed from 
> String[]
> to Object[]?

this allows parameters to be set in more flexible ways (rather than just 
from the xml). in particular, this changed allowed parameters to be set to 
objects on the main digester stack. the present code should ensure that 
these objects are not be converted but strings are.

> 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

i'm now thinking along the lines that maybe all nulls and any objects 
which are not compatible with the given parameter type should be converted.
  this should be backwards compatible (the exception thrown when an 
incompatible type is passed prevents digestion continuing) and give extra 
functionality whilst probably also fixing the reported problem. what do 
people think about this plan?

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

i'm not sure and that's why i'd like more information. i'm having trouble 
constructing a test case and without a failed test case, i'm very 
reluctant to patch.

- robert


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


Re: [Digester] problem calling methods with a primitive parameter

Posted by Mohan Kishore <mo...@yahoo.com>.
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 <ro...@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


Re: [Digester] problem calling methods with a primitive parameter but no xml attribute specified

Posted by robert burrell donkin <ro...@blueyonder.co.uk>.
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