You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by "David Birch (JIRA)" <ji...@apache.org> on 2007/05/02 12:11:15 UTC

[jira] Updated: (BEANUTILS-276) Exceptions when setting properties to null (specific types only)

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

David Birch updated BEANUTILS-276:
----------------------------------

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




  was:
for the following types attempting to set a property to null 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





> 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