The spec. supports the following:
 
setFoo(int index, Object[] array)
 
However, BeanUtils.populate() does not.  The problem is that
BeanUtils.populate() isn't checking if the second parameter is an array
or not, it only checks the first parameter.  However, the JavaBean spec.
allows for the second paramter to be of an array type.  If you try this,
you will find that it doesn't work in struts1.0 or struts1.0.1 unless
you make the change to the code that I suggested below.  If you look at
the code, the bug is very obivious.
 

        -----Original Message----- 
        From: Arron Bates 
        Sent: Sun 1/13/2002 11:31 PM 
        To: Struts Users Mailing List 
        Cc: 
        Subject: Re: Bug in BeanUtils.populate()
        
        

        BeanUtils works correctly in that if you want to set against an
index,
        you can have the following forms.
        
        Quoted from the bean spec --==>>
        
        void setter(int index, PropertyType value); // indexed setter
        PropertyType getter(int index);             // indexed getter
        
        void setter(PropertyType values[]);         // array setter
        PropertyType[] getter();                    // array getter
        
        ...so it's either setting and getting an entire array
collection, or
        directly setting and getting objects against an index which can
mean
        absolutely anything internally to the bean. The BeanUtils class
uses
        separate code blocks to handle both.
        
        Builds as of a few days ago will accept implementations of
        java.util.List as well as the primitive arrays the spec defines.
        
        I think the ones you're after are the array methods.
        
        Arron.
        
        >It appears there is a bug in BeanUtils.populate() for an
indexed setter
        >of array type.  It doesn't take into account that it is an
indexed
        >setter and that the second parameter is an array because it
only checks
        >the first parameter which is always an int for an indexed
setter.  This
        >is the code in the 1.0.1 release:
        >
        >           ...
        >            Class parameterType = parameterTypes[0];
        >            if (parameterTypes.length > 1)
        >                parameterType = parameterTypes[1];      //
Indexed
        >setter
        >            // Convert the parameter value as required for this
setter
        >method
        >            Object parameters[] = new Object[1];
        >            if (parameterTypes[0].isArray()) {
        >          ...
        >
        >it should be as follows:
        >
        >           ...
        >            Class parameterType = parameterTypes[0];
        >            if (parameterTypes.length > 1)
        >                parameterType = parameterTypes[1];      //
Indexed
        >setter
        >            // Convert the parameter value as required for this
setter
        >method
        >            Object parameters[] = new Object[1];
        >            if (parameterType.isArray()) {
        >          ...
        >
        >
        
        
        
        --
        To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
        For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>
        
        


Attachment: winmail.dat
Description: application/ms-tnef

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to