[jira] [Commented] (LANG-881) NumberUtils.createNumber() does not work for octal numbers

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

[jira] [Commented] (LANG-881) NumberUtils.createNumber() does not work for octal numbers

David Costanzo (Jira)

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

Sebb commented on LANG-881:

I suspect that is because it uses createLong() and createBigInteger() which used not to handle octal prefixes.
This was fixed in 3.1 and 3.2 (not yet released) respectively.

So createNumber() should now handle octal numbers for all integral sizes, i.e. I think the Javadoc is wrong.
There are already tests which show the behaviour implicitly, for example:
assertEquals(Integer.class, NumberUtils.createNumber("017777777777").getClass()); // 31 bits
assertEquals(Long.class,    NumberUtils.createNumber("037777777777").getClass()); // 32 bits

These should be extended/amended to check the value as well.

>  NumberUtils.createNumber() does not work for octal numbers
> -----------------------------------------------------------
>                 Key: LANG-881
>                 URL: https://issues.apache.org/jira/browse/LANG-881
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.math.*
>    Affects Versions: 3.1
>            Reporter: Michiel Kalkman
>            Priority: Minor
> The javadoc for NumberUtils.createNumber() states:
> "Values with leading 0's will not be interpreted as octal."
> However,
> assertEquals(25, NumberUtils.createNumber("0025"));
> fails, because NumberUtils.createNumber("0025") returns 21.

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira