commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sebb (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (LANG-992) NumberUtils#isNumber() returns false for "0.0", "0.4790", et al
Date Thu, 27 Mar 2014 12:28:17 GMT

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

Sebb commented on LANG-992:
---------------------------

Should octal numbers be validated or not?
Clearly a number such as 0xdefgh is invalid, because the 0x prefix unambiguosly identifies
a hex number.
However 0123 is potentially equally valid as an octal and a decimal number. 
Which is correct depends on the context.

Now the Javadoc for isNumber says "Checks whether the String a valid Java number."
If we take that to mean that the digit string must be valid as a numeric Java literal, then
clearly the leading 0 means octal.
However, numeric literals are not Strings.
JVM methods such as Integer.decode(String) that treat a leading 0 as meaning octal will reject
a parameter that contains non-octal digits - so again that suggests octal should be validated.

As far as I know, there are no standard Java methods that accept number type suffixes in Strings.
I think these are only accepted in numeric literals.

The fact that isNumber() accepts all these formats leads me to the conclusion that the intention
was probably to support the same syntax as Java literals, and so the code should validate
octal numbers accordingly.

> NumberUtils#isNumber() returns false for "0.0", "0.4790", et al
> ---------------------------------------------------------------
>
>                 Key: LANG-992
>                 URL: https://issues.apache.org/jira/browse/LANG-992
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.math.*
>    Affects Versions: 3.3.1
>         Environment: Java 8, Windows 7
>            Reporter: Adam Rauch
>             Fix For: Review Patch
>
>         Attachments: LANG-992-v2.patch
>
>
> After upgraded from 3.1 to 3.3.1 it seems that {{isNumber(String str)}} returns false
for decimal numbers with leading zeros. In other words:
> {code:java}
> boolean ret = NumberUtils.isNumber("0.4790");
> {code}
> On 3.1, {{ret}} was true. In 3.3.1, {{ret}} is false.
> Guessing that LANG-972 is related... comment in the code states:
> {code:java}
> // leading 0, but not hex, must be octal
> {code}
> This is clearly a case where leading 0 does not mean hex.



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

Mime
View raw message