commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rob Tompkins (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (LANG-1252) NumberUtils.isNumber and NumberUtils.createNumber resolve inconsistently
Date Thu, 11 Aug 2016 14:34:20 GMT

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

Rob Tompkins edited comment on LANG-1252 at 8/11/16 2:33 PM:
-------------------------------------------------------------

Regarding LANG-1038, {{NumberUtils.isNumber("-2")}} returns {{true}}. However, {{NumberUtils.isNumber("+2")}}
returns {{false}}. Further, *in Java 1.6*, the following throw exceptions:
{code:java}
Byte.parseByte("+2");
Integer.parseInt("+2");
Long.parseLong("+2");
Short.parseShort("+2");
{code}
whereas the following succeed,
{code:java}
Double.parseDouble("+2");
Float.parseFloat("+2");
{code}

_*Note.*_ Benedikt suggested that {{NumberUtils.parseNumber(str)}} should not throw a {{NumberFormatException}}
and return a valid {{java.lang.Number}} if and only if {{NumberUtils.isParsable(str)}} returns
true for the same {{str}}. This seems to not be the case as:
{code:java}
NumberUtils.isParsable("+2"); // false
NumberUtils.parseNumber("+2"); // the value 2
{code}

This may be because in Java 6 only Float and Double return with a Valid number without exception.


was (Author: chtompki):
Regarding LANG-1038, {{NumberUtils.isNumber("-2")}} returns {{true}}. However, {{NumberUtils.isNumber("+2")}}
returns {{false}}. Further the following throw exceptions:
{code:java}
Byte.parseByte("+2");
Integer.parseInt("+2");
Long.parseLong("+2");
Short.parseShort("+2");
{code}
whereas the following succeed,
{code:java}
Double.parseDouble("+2");
Float.parseFloat("+2");
{code}

_*Note.*_ Benedikt suggested that {{NumberUtils.parseNumber(str)}} should not throw a {{NumberFormatException}}
and return a valid {{java.lang.Number}} if and only if {{NumberUtils.isParsable(str)}} returns
true for the same {{str}}. This seems to not be the case as:
{code:java}
NumberUtils.isParsable("+2"); // false
NumberUtils.parseNumber("+2"); // the value 2
{code}

This may be because in Java 6 only Float and Double return with a Valid number without exception.

> NumberUtils.isNumber and NumberUtils.createNumber resolve inconsistently
> ------------------------------------------------------------------------
>
>                 Key: LANG-1252
>                 URL: https://issues.apache.org/jira/browse/LANG-1252
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.math.*
>    Affects Versions: 3.4
>            Reporter: Rob Tompkins
>             Fix For: Discussion
>
>
> In considering the issues LANG-1060, LANG-1040, LANG-1038, and LANG-992, it seems that
there are times when {{NumberUtils.isNumber}} resolves to {{false}} while {{NumberUtils.createNumber}},
given the same input, does not throw an exception, returning a valid {{java.lang.Number}}.
This inconsistency should be resolved either by making {{isNumber}} more lenient or {{createNumber}}
more stringent.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message