commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Josef Cacek (JIRA)" <j...@apache.org>
Subject [jira] Commented: (BEANUTILS-283) ConvertUtilsBean doesn't handl conversion to String correctly
Date Mon, 11 Jun 2007 14:55:26 GMT

    [ https://issues.apache.org/jira/browse/BEANUTILS-283?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12503425
] 

Josef Cacek commented on BEANUTILS-283:
---------------------------------------

toString could be OK, but only if it's used for the right value. Here it is not.

The simplest solution for this bug could be:
if (targetType == String.class && value != null) {
  converted = converted.toString();
}

or 
if (converted==null && targetType == String.class && value != null) {
  converted = value.toString();
}

I will attach sample application.

> ConvertUtilsBean doesn't handl conversion to String correctly
> -------------------------------------------------------------
>
>                 Key: BEANUTILS-283
>                 URL: https://issues.apache.org/jira/browse/BEANUTILS-283
>             Project: Commons BeanUtils
>          Issue Type: Bug
>          Components: ConvertUtils & Converters
>    Affects Versions: Nightly Builds
>         Environment: commons-beanutils-20070610-src.zip
>            Reporter: Josef Cacek
>
> Either lookup(Class, Class) or convert(Object, Class) method doesn't work correctly in
class ConvertUtilsBean.
> Problematic is the case when target class is String.
> The code from convert(..) which doesn't work:
>         Object converted = value;
>         Converter converter = lookup(sourceType, targetType);
>         if (converter != null) {
>             if (log.isTraceEnabled()) {
>                 log.trace("  Using converter " + converter);
>             }
>             converted = converter.convert(targetType, value);
>         }
> // here we already have converted value (String), but we will rewrite it by default .toString()
- it's a bug
>         if (targetType == String.class && value != null) {
>             converted = value.toString();
>         }

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