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

Niall Pemberton commented on BEANUTILS-283:
-------------------------------------------

My understanding of String's toString() method is that it just returns a 
reference to itself - so why is this a bug?

Just for the record the reason for using the converted values toString() method 
is because Converter implementations in BeanUtils in the past have not taken 
any account of the "target type" passed to the Converter's convert() method. 
Also ConvertUtils used to delegate to StringConverter for conversions to 
Strings - now ConvertUtils delegates to the converter for the type of the value 
being converted. Hence the reason for using toString() - to try and ensure that 
conversion to String still works with existing user Converter implementations.

> 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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to