[
https://issues.apache.org/jira/browse/BEANUTILS-445?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13799985#comment-13799985
]
Oliver Heger commented on BEANUTILS-445:
----------------------------------------
The following unit test (added to {{NumberConverterTestBase}} demonstrates the
problem:
{code}
/**
* Tests a conversion to an unsupported type if a default value is set.
*/
public void testInvalidTypeWithDefault() {
NumberConverter converter = makeConverter(numbers[1]);
try {
converter.convert(Object.class, numbers[0]);
fail("Invalid type with default test, expected
ConversionException");
} catch(ConversionException e) {
// expected result
}
}
{code}
> Converters can return an invalid result object if a default value is set
> ------------------------------------------------------------------------
>
> Key: BEANUTILS-445
> URL: https://issues.apache.org/jira/browse/BEANUTILS-445
> Project: Commons BeanUtils
> Issue Type: Bug
> Components: ConvertUtils & Converters
> Affects Versions: 1.8.3
> Reporter: Oliver Heger
> Fix For: LATER THAN 1.8.4
>
>
> For BeanUtils converters derived from {{AbstractConverter}} it is possible to
> set a default value. If the default flag is set, this value is returned for
> *null* input, but also if a conversion to an unsupported type is attempted
> (in this case, a conversion of the default value to the target class is
> tried, but if this fails, the default value is returned directly). This
> causes the converter to return an object of another class than requested.
> IMHO this is a source of ClassCastExceptions and should be changed. A
> converter should never return an object of a different type than the
> requested target class. So either perform a successful conversion (if
> necessary, convert the default value to the target class) or throw an
> exception.
--
This message was sent by Atlassian JIRA
(v6.1#6144)