You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Gary D. Gregory (JIRA)" <ji...@apache.org> on 2012/06/30 16:09:44 UTC
[jira] [Commented] (CLI-226) createNumber() in TypeHandler cannot
work with some Locale
[ https://issues.apache.org/jira/browse/CLI-226?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13404503#comment-13404503 ]
Gary D. Gregory commented on CLI-226:
-------------------------------------
The nice way to fix this is to rewrite {{org.apache.commons.cli.TypeHandler.createNumber(String)}} like this:
{code:java}
public static Number createNumber(String str) throws ParseException
{
try
{
return NumberFormat.getNumberInstance().parse(str);
}
catch (NumberFormatException e)
{
throw new ParseException(e.getMessage());
} catch (java.text.ParseException e)
{
throw new ParseException(e.getMessage());
}
}
{code}
But this makes one assert fail in {{org.apache.commons.cli.PatternOptionBuilderTest.testNumberPattern()}}
Thoughts?
> createNumber() in TypeHandler cannot work with some Locale
> ----------------------------------------------------------
>
> Key: CLI-226
> URL: https://issues.apache.org/jira/browse/CLI-226
> Project: Commons CLI
> Issue Type: Bug
> Affects Versions: 1.2
> Reporter: Olivier Sechet
> Labels: i18n
>
> The {{createNumber()}} method in the {{TypeHandler}} class expects the decimal separator to be a dot ({{'.'}}). However the dot is not used in all the languages as a decimal separator. Most of the European countries, Russia and a lot of others countries uses a comma ({{','}}).
> With the corresponding {{Locale}}, the {{createNumber()}} method fails, throwing an exception.
> For example:
> {code:title=Type.java|borderStyle=solid}
> public class Type {
> public static void main(final String[] args) {
> java.util.Locale.setDefault(java.util.Locale.GERMANY);
> String text = java.text.NumberFormat.getNumberInstance().format(12.34);
> Number nb = org.apache.commons.cli.TypeHandler.createNumber(text);
> System.out.println(nb);
> }
> }
> {code}
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira