You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Jing Zhou <ji...@netspread.com> on 2002/04/12 20:08:03 UTC

The Exception/Bug in STRUTS B1 example

Hi, struts developers,

I posted the problem on 04/03 in struts user group and
hope the problem will be fixed in struts 1.1 final release.

Take a look at the example page html-link.jsp in
struts-exercise-taglib and click the 'Cancel' button.
An exception is thrown with message:
'array element type mismatch' 
by PropertyUtils.setIndexedProperty().

I looked at the root cause and found that
the TestBean has no indexed method for stringArray
while the PropertyUtils is invoking setIndexedProperty
method when it sees the property stringArray[0]
posted from the html-link.jsp.

A theoretical fix is to change BeanUtils.populate
method above the section '// Convert the parameter
value as required for this setter method'

Original section:
    if(parameterTypes.length > 1)
        parameterType = parameterTypes[1];   // Indexed or mapped setter

Change to:
     if(parameterTypes.length > 1) {
          parameterType = parameterTypes[1]; // Indexed or mapped setter
     } else {
          // The normal process will use parameterType from parameterTypes[0]
          // But we have a special case:
          int nestedDelim = name.lastIndexOf(PropertyUtils.NESTED_DELIM);
          int indexedDelim = name.lastIndexOf(PropertyUtils.INDEXED_DELIM);
          if(indexedDelim > nestedDelim) {
               // At this point, PropertyUtils will invoke setIndexedProperty later,
               // but it will use a wrong parameterType.
               // So, we change the parameter type to its component type,
               // then everything will follow the same processing.
                if(parameterType.isArray()) {
                    parameterType = parameterType.getComponentType();
                 }
           }
      }

I had tested the fix and no exception anymore and hope this will provide
a double checking for the developer who is fixing the problem on a
theoretical ground. Another way is that you have to change the
TestBean class to add an indexed method for stringArray (but that will
make struts less stable)

If anyone can confirm the bug, I can submit the bug to the database
for you.

Thanks,
Jing