BeanUtils.setProperty: crashes when setting a java.util.Date simple property
with a java.sql.Timestamp value
------------------------------------------------------------------------------------------------------------
Key: BEANUTILS-275
URL: https://issues.apache.org/jira/browse/BEANUTILS-275
Project: Commons BeanUtils
Issue Type: Bug
Components: Bean / Property Utils
Affects Versions: 1.7.0
Environment: Test done on JVM 1.4.2 running on Windows 2000
Reporter: adelino
Priority: Blocker
BeanUtils.setProperty method converts a value of type java.sql.Timestamp to
java.lang.String no matter the type of the property at the receiving end:
Timestamp selectedDate = new Timestamp( System.currentTimeMillis() );
// Class of target object has a getter and setter for property selectedDate of
type java.util.Date
BeanUtils.setProperty(target, "selectedDate", selectedDate);
// THIS THROWS AN EXCEPTION java.lang.IllegalArgumentException - argument type
mismatch
Looking into the source code of the setProperty method I suspect that the
following piece of code needs to be changed:
} else if (getConvertUtils().lookup(value.getClass()) != null) {
newValue = getConvertUtils().convert(value.toString(), type);
} else {
Indeed getConvertUtils().lookup(value.getClass()) returns a non null result
since there is a converter registered for java.sql.Timestamp . The problem is
that the newValue gets assigned with a String (because of value.toString())
whereas, at the beginning, we had an object assignable to java.util.Date
without any conversion.
I have also checked the HEAD version of BeanUtils in SVN and this faulty piece
of code is still there.
Please could fix this bug... Many thanks.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]