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] Created: (BEANUTILS-276) Exceptions when setting properties to null (specific types only)
Date Wed, 02 May 2007 10:09:15 GMT
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 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