You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by "adelino (JIRA)" <ji...@apache.org> on 2007/04/25 10:28:15 UTC

[jira] Created: (BEANUTILS-275) BeanUtils.setProperty: crashes when setting a java.util.Date simple property with a java.sql.Timestamp value

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: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


[jira] Resolved: (BEANUTILS-275) BeanUtils.setProperty: crashes when setting a java.util.Date simple property with a java.sql.Timestamp value

Posted by "Niall Pemberton (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/BEANUTILS-275?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Niall Pemberton resolved BEANUTILS-275.
---------------------------------------

    Resolution: Duplicate

This has been resolved by the changes implemented as part of BEANUTILS-258

> 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: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org