commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "David Birch (JIRA)" <j...@apache.org>
Subject [jira] Reopened: (BEANUTILS-276) Exceptions when setting properties to null (specific types only)
Date Wed, 02 May 2007 16:23:15 GMT

     [ https://issues.apache.org/jira/browse/BEANUTILS-276?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

David Birch reopened BEANUTILS-276:
-----------------------------------


Hi,
  sorry, but i can't really see where the logic lies in not being able to set any of those
types to null using the std config of converters - i realise that each of the types mentioned
do not have no-args constructors, but we're not trying to construct, we're just trying to
set a bean property with a legal value (null).

thanks
David


> Exceptions when setting properties to null (specific types only)
> ----------------------------------------------------------------
>
>                 Key: BEANUTILS-276
>                 URL: https://issues.apache.org/jira/browse/BEANUTILS-276
>             Project: Commons BeanUtils
>          Issue Type: Bug
>          Components: ConvertUtils & Converters
>    Affects Versions: 1.7.0
>         Environment: java 1.4.2, 1.5.0
>            Reporter: David Birch
>
> for the following types attempting to set a property to null using BeanUtils.setProperty(java.lang.Object,
java.lang.String, java.lang.Object) will result in an Exception
> java.math.BigDecimal
> java.math.BigInteger
> java.net.URL
> java.io.File
> java.sql.Date
> java.sql.Time
> java.sql.Timestamp
> all primitive wrappers work fine, as does java.util.Date
> sample stacktrace is
> Failed Set empty [bigDecimal1]
> org.apache.commons.beanutils.ConversionException: No value specified
> 	at org.apache.commons.beanutils.converters.BigDecimalConverter.convert(BigDecimalConverter.java:103)
> 	at org.apache.commons.beanutils.ConvertUtilsBean.convert(ConvertUtilsBean.java:428)
> 	at org.apache.commons.beanutils.BeanUtilsBean.setProperty(BeanUtilsBean.java:1002)
> 	at org.apache.commons.beanutils.BeanUtils.setProperty(BeanUtils.java:313)
> 	at com.marsh.ste.testing.steps.DataStepUT.testChanges(DataStepUT.java:52)
> The converter classes seem to sort of have an option to handle null inputs by returning
a default value - from BigDecimalConverter.convert()
>       if (value == null) {
>             if (useDefault) {
>                 return (defaultValue);
>             } else {
>                 throw new ConversionException("No value specified");
>             }
>         }
> though i am not totally sure, might be better to fix this in the BeanUtilsBean.setProperty
method, add some other cases - block starting line 1001
>             if ((value instanceof String) || (value == null)) {
>                 newValue = getConvertUtils().convert((String) value, type);
>             } else if (value instanceof String[]) {
>                 newValue = getConvertUtils().convert(((String[]) value)[0],
>                                                 type);
>             } else if (getConvertUtils().lookup(value.getClass()) != null) {
>                 newValue = getConvertUtils().convert(value.toString(), type);
>             } else {
>                 newValue = value;
>             }
> cheers
> David

-- 
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


Mime
View raw message