You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Juan Pablo Santos Rodríguez (JIRA)" <ji...@apache.org> on 2014/04/26 11:24:15 UTC
[jira] [Comment Edited] (LANG-997) NumberUtil#isNumber() returns
false for "012345678" but not for "12345678"
[ https://issues.apache.org/jira/browse/LANG-997?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13981930#comment-13981930 ]
Juan Pablo Santos Rodríguez edited comment on LANG-997 at 4/26/14 9:22 AM:
---------------------------------------------------------------------------
Hi,
the issue isn't only with "too big" numbers, f.ex., "01258" also returns false. Consider this code:
{code}
@Test
public void isNumber() {
Number n = new Integer( "01258" ); // notice we're using a String, as NumberUtil.isNumber does, trying to use 01258 without quotes results in a compilation error
Assert.assertTrue( n.intValue() == 1258 );
n = new Integer( "Unicorn" ) // -> NFException, expect NumberUtils.isNumber to return false here, as it does
}
{code}
I expect isNumber to return true; Furthermore, it was returning true before 3.3.x.. Agree with the isJavaNumber method need instead of changing behaviour.
was (Author: juanpablo):
Hi,
the issue isn't only with "too big" numbers, f.ex., "01258" also returns false. Consider this code:
{code}
@Test
public void isNumber() {
Number n = new Integer( "01258" ); // notice we're using a String, as NumberUtil.isNumber does, trying to use 01258 without quotes results in a compilation error
Assert.assertTrue( n.intValue() == 1258 );
n = new Integer( "Unicorn" ) // -> NFException, expect NumberUtils.isNumber to return false here, as it does
}
{code}
I expect isNumber to return true; Furthermore, it was returning true before 3.3.x.. Agree with the isJavaNumber method need instead of chaning behaviour
> NumberUtil#isNumber() returns false for "012345678" but not for "12345678"
> --------------------------------------------------------------------------
>
> Key: LANG-997
> URL: https://issues.apache.org/jira/browse/LANG-997
> Project: Commons Lang
> Issue Type: Bug
> Components: lang.math.*
> Affects Versions: 3.3.2
> Environment: Java 6
> Reporter: Juan Pablo Santos Rodríguez
> Fix For: Review Patch, Discussion, 3.4
>
>
> With commons-lang 3.2.1:
> {code}
> boolean ret = NumberUtils.isNumber( "012345678901234567" );
> {code}
> returns {{true}}, but for 3.3.2, returns {{false}}.
> The change seems to be introduced in LANG-972 / LANG-992, as it seems to consider now that, if the parameter string has a leading 0, and it's not hex, then it must be forcibly octal.
> As previous 3.x versions accept 0ddd as valid decimal numbers, the suggested change on NumberUtils#isNumber, is to replace lines [1367-1376|http://commons.apache.org/proper/commons-lang/xref/org/apache/commons/lang3/math/NumberUtils.html#L1367] with:
> {code}
> } else if (Character.isDigit(chars[start + 1])) {
> // leading 0, but not hex, must be octal or decimal
> int i = start + 1;
> for (; i < chars.length; i++) {
> if (chars[i] < '0' || chars[i] > '9') { // was: if (chars[i] < '0' || chars[i] > '7') {
> return false;
> }
> }
> return true;
> }
> {code}
--
This message was sent by Atlassian JIRA
(v6.2#6252)