commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Manuel Dominguez Sarmiento (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (BEANUTILS-458) BaseLocaleConverter.checkConversionResult() fails with ConversionException when result is null when it should not
Date Mon, 03 Mar 2014 16:55:28 GMT

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

Manuel Dominguez Sarmiento edited comment on BEANUTILS-458 at 3/3/14 4:55 PM:
------------------------------------------------------------------------------

The following code will reproduce the issue. It seems this is triggered when a defaultValue
of null is used:

import java.util.Locale;

import org.apache.commons.beanutils.Converter;
import org.apache.commons.beanutils.locale.converters.IntegerLocaleConverter;

public class Test {

	public static void main(String[] args) {
		Converter converter = new IntegerLocaleConverter(null, Locale.US);
                // THIS WILL ALSO FAIL IF "null" IS PASSED,
                // INSTEAD OF AN EMPTY STRING
		Integer result = converter.convert(Integer.class, "");
		System.out.println(result);
	}
}


Result:

Exception in thread "main" org.apache.commons.beanutils.ConversionException: Unsupported target
type: class java.lang.Integer
	at org.apache.commons.beanutils.locale.BaseLocaleConverter.checkConversionResult(BaseLocaleConverter.java:287)
	at org.apache.commons.beanutils.locale.BaseLocaleConverter.getDefaultAs(BaseLocaleConverter.java:262)
	at org.apache.commons.beanutils.locale.BaseLocaleConverter.convert(BaseLocaleConverter.java:223)
	at org.apache.commons.beanutils.locale.BaseLocaleConverter.convert(BaseLocaleConverter.java:201)
	at Test.main(Test.java:10)




was (Author: mads1980):
The following code will reproduce the issue. It seems this is triggered when a defaultValue
of null is used:

import java.util.Locale;

import org.apache.commons.beanutils.Converter;
import org.apache.commons.beanutils.locale.converters.IntegerLocaleConverter;

public class Test {

	public static void main(String[] args) {
		Converter converter = new IntegerLocaleConverter(null, Locale.US);
		Integer result = converter.convert(Integer.class, ""); // THIS WILL ALSO FAIL IF "null"
IS PASSED, INSTEAD OF AN EMPTY STRING
		System.out.println(result);
	}
}


Result:

Exception in thread "main" org.apache.commons.beanutils.ConversionException: Unsupported target
type: class java.lang.Integer
	at org.apache.commons.beanutils.locale.BaseLocaleConverter.checkConversionResult(BaseLocaleConverter.java:287)
	at org.apache.commons.beanutils.locale.BaseLocaleConverter.getDefaultAs(BaseLocaleConverter.java:262)
	at org.apache.commons.beanutils.locale.BaseLocaleConverter.convert(BaseLocaleConverter.java:223)
	at org.apache.commons.beanutils.locale.BaseLocaleConverter.convert(BaseLocaleConverter.java:201)
	at Test.main(Test.java:10)



> BaseLocaleConverter.checkConversionResult() fails with ConversionException when result
is null when it should not
> -----------------------------------------------------------------------------------------------------------------
>
>                 Key: BEANUTILS-458
>                 URL: https://issues.apache.org/jira/browse/BEANUTILS-458
>             Project: Commons BeanUtils
>          Issue Type: Bug
>          Components: ConvertUtils & Converters
>    Affects Versions: 1.9.0, 1.9.1
>            Reporter: Manuel Dominguez Sarmiento
>            Priority: Critical
>             Fix For: 1.9.2
>
>
> Null is a valid result for many, if not all converters. However, since BEANUTILS-445,
this will always fail with ConversionException
> https://issues.apache.org/jira/browse/BEANUTILS-445



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Mime
View raw message