DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=4174>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=4174

PropertyUtils.setSimpleProperty throws exception on dissimilar types

           Summary: PropertyUtils.setSimpleProperty throws exception on
                    dissimilar types
           Product: Struts
           Version: 1.0 Final
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: Minor
          Priority: Other
         Component: Utilities
        AssignedTo: [EMAIL PROTECTED]
        ReportedBy: [EMAIL PROTECTED]


PropertyUtils.setSimpleProperty is used by CopyProperties in order to 
(typically) copy properties from a data bean to an action form bean or vice-
versa.  But, not all getters/setters will always have matching types.  
CopyProperties throws an exception if setters/getters of the same name exist, 
but have differing types.  This causes a problem, for example if your data bean 
class has a property:

Manager manager;
Manager getManager();

And the ActionForm bean has a property:

String manager;
String getManager();

Where String manager might represent the object ID or primary key of a 
manager.  In this case, additional mapping between properties often follows the 
CopyProperties call.  But with the exception being thrown, CopyProperties 
doesn't finish its job and copy the rest of the *valid* properties.  

What we did to get around this for now is to use a subclass of PropertyUtils 
that overrides setSimplePropery and adds code similar to the following:

Class params[] = writeMethod.getParameterTypes();
if(!(value.getClass().isInstance(params[0])))
    throw new NoSuchMethodException("Property '" + name +
        "' has no setter method of the same type");

This alters the behavior to throw an exception that CopyProperties can ignore 
so that if types don't match it can continue copying the other properties that 
do.  Is this something that should be added to the original method in 
PropertyUtils?

Reply via email to