It isn't ignorance, we just weren't on the same page.  :)

Anyway, I filed a bug in commons back in October or ealy November.  I
was hoping it would have been fixed by now, but it appears it hasn't...

I have tested my change and it works fine.

-----Original Message-----
From: Arron Bates [mailto:[EMAIL PROTECTED]]
Sent: Monday, January 14, 2002 3:03 PM
To: Struts Users Mailing List
Subject: Re: Bug in BeanUtils.populate()


I get what you're trying to do now.
Sorry about all that.

If you can test your change and make a CVS diff of the changes, why 
don't you log a bugzilla bug in commons and submit it to the commons dev

list?...
 ...otherwise I can look into it for you.

Once again, sorry about the ignorance.


Arron.

Jason Chaffee wrote:

>Again, you are missing the point.  The following is allowed:
>
>void setFoo(int index, PropertyType value)
>
>This means that the PropertyType can be of the type Object[].
>
>-----Original Message-----
>From: Arron Bates [mailto:[EMAIL PROTECTED]]
>Sent: Monday, January 14, 2002 2:36 PM
>To: Struts Users Mailing List
>Subject: Re: Bug in BeanUtils.populate()
>
>
>Here is the spec...
>
>http://java.sun.com/products/javabeans/docs/beans.101.pdf
>
>
>...where in it does it have...
>
>void setFoo(int index, Object[] array)
>
>...?  Indexed methods description starts on page 40, and go over to 41.
>
>
>Arron.
>
>Jason Chaffee wrote:
>
>>Let me try to clearify this again.  The following is supported by the
>>JavaBean spec.
>>
>>void setFoo(int index, Object[] array)
>>
>>where Object[] is the Propertytype.
>>
>>This means that foo is an array of arrays.  Now, look at the code
>>snippet from BeanUtils.populate(), you will notice that there is
>>
>special
>
>>logic to handle a parameterType that is an array.  However, this check
>>is only checking the first parameter.  In other words, it doesn't
>>account for the fact that the second parameter in an indexed setter
may
>>be of array type.  In particular, see the line, if
>>(parameterTypes[0].isArray()), this should be, if
>>(parameterType.isArray()).  This would account for an indexed setter
>>
>and
>
>>it would handle the logic if it is of type array.  The bug is really
>>quite obivious when looking at the code.
>>
>>           Class parameterTypes[] = setter.getParameterTypes();
>>           /*
>>           if (debug >= 1)
>>               System.out.println("    Setter method is '" +
>>                                  setter.getName() + "(" +
>>                                  parameterTypes[0].getName() +
>>                                  (parameterTypes.length > 1 ?
>>                                   ", " + parameterTypes[1].getName()
>>
>:
>
>>"" )
>>                                  + ")'");
>>           */
>>           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()) {
>>               if (value instanceof String) {
>>                   String values[] = new String[1];
>>                   values[0] = (String) value;
>>                   parameters[0] = ConvertUtils.convert((String[])
>>values,
>>                   parameterType);
>>               } else if (value instanceof String[]) {
>>                   parameters[0] = ConvertUtils.convert((String[])
>>value,
>>                   parameterType);
>>               } else {
>>                   parameters[0] = value;
>>               }
>>           } else {
>>               if (value instanceof String) {
>>                   parameters[0] = ConvertUtils.convert((String)
>>
>value,
>
>>                   parameterType);
>>               } else if (value instanceof String[]) {
>>                   parameters[0] = ConvertUtils.convert(((String[])
>>value)[0],
>>                   parameterType);
>>               } else {
>>                   parameters[0] = value;
>>               }
>>           }
>>
>>-----Original Message-----
>>From: Arron [mailto:[EMAIL PROTECTED]]
>>Sent: Monday, January 14, 2002 2:55 AM
>>To: Struts Users Mailing List
>>Subject: Re: Bug in BeanUtils.populate()
>>
>>
>>The method definitions were literally cut-and-paste from the spec.
>>There is no other code in the spec relating to indexed properties.
>>
>>Arron.
>>
>>
>>Jason Chaffee wrote:
>>
>>>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]>
>>>     
>>>     
>>>
>>>
>>>---------------------------------------------------------------------
-
>>>
>-
>
>>-
>>
>>>--
>>>To unsubscribe, e-mail:
>>>
>><mailto:[EMAIL PROTECTED]>
>>
>>>For additional commands, e-mail:
>>>
>><mailto:[EMAIL PROTECTED]>
>>
>>>winmail.dat
>>>
>>>Content-Type:
>>>
>>>application/ms-tnef
>>>Content-Encoding:
>>>
>>>base64
>>>
>>>
>>>
>>----------------------------------------------------------------------
-
>>
>-
>
>>>Part 1.3
>>>
>>>Content-Type:
>>>
>>>text/plain
>>>
>>>
>>
>>
>>--
>>To unsubscribe, e-mail:
>><mailto:[EMAIL PROTECTED]>
>>For additional commands, e-mail:
>><mailto:[EMAIL PROTECTED]>
>>
>>
>>--
>>To unsubscribe, e-mail:
>>
><mailto:[EMAIL PROTECTED]>
>
>>For additional commands, e-mail:
>>
><mailto:[EMAIL PROTECTED]>
>
>>
>
>
>
>--
>To unsubscribe, e-mail:
><mailto:[EMAIL PROTECTED]>
>For additional commands, e-mail:
><mailto:[EMAIL PROTECTED]>
>
>
>--
>To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
>For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>
>
>



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


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

Reply via email to