You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "ASF GitHub Bot (Jira)" <ji...@apache.org> on 2021/03/04 15:19:00 UTC

[jira] [Work logged] (LANG-1645) NumberUtils.createNumber/createBigInteger fails on hexidecimal integers prefixed with +

     [ https://issues.apache.org/jira/browse/LANG-1645?focusedWorklogId=560991&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-560991 ]

ASF GitHub Bot logged work on LANG-1645:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 04/Mar/21 15:18
            Start Date: 04/Mar/21 15:18
    Worklog Time Spent: 10m 
      Work Description: aherbert opened a new pull request #728:
URL: https://github.com/apache/commons-lang/pull/728


   Address the issue that NumberUtils.isCreatable("+0xF") is true but NumberUtils.createNumber("+0xF") fails.
   
   Also added support for the optional + prefix in NumberUtils.createBigInteger.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Issue Time Tracking
-------------------

            Worklog Id:     (was: 560991)
    Remaining Estimate: 0h
            Time Spent: 10m

> NumberUtils.createNumber/createBigInteger fails on hexidecimal integers prefixed with +
> ---------------------------------------------------------------------------------------
>
>                 Key: LANG-1645
>                 URL: https://issues.apache.org/jira/browse/LANG-1645
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.math.*
>    Affects Versions: 3.12.0
>            Reporter: Alex Herbert
>            Assignee: Alex Herbert
>            Priority: Minor
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> The Java Language Specification allows an optional sign prefix for a number as + or -.
> A + sign before a hex integer is not recognised by createNumber and createBigInteger but is recognised by isCreatable, createInteger and createLong. The two later functions delegate to Java's decode() function that handles an optional leading +.
> The following demonstrates the tests that fail but would pass if the leading '+' is removed.
> {code:java}
>     @Test
>     void testCreatePositiveHexInteger() {
>         // Hex is only supported for integers so no test for hex floating point formats
>         assertTrue(NumberUtils.isCreatable("+0xF"));
>         assertTrue(NumberUtils.isCreatable("+0xFFFFFFFF"));
>         assertTrue(NumberUtils.isCreatable("+0xFFFFFFFFFFFFFFFFF"));
>         assertEquals(Integer.decode("+0xF"), NumberUtils.createInteger("+0xF"));
>         assertEquals(Long.decode("+0xFFFFFFFF"), NumberUtils.createLong("+0xFFFFFFFF"));
>         assertEquals(new BigInteger("+FFFFFFFFFFFFFFFF", 16),
>                      NumberUtils.createBigInteger("0xFFFFFFFFFFFFFFFF"));
>         try {
>             assertEquals(new BigInteger("+FFFFFFFFFFFFFFFF", 16),
>                          NumberUtils.createBigInteger("+0xFFFFFFFFFFFFFFFF"));
>             Assertions.fail("This should be possible but it is not");
>         } catch (NumberFormatException ex) {
>             // This should not happen
>         }
>         assertEquals(Integer.decode("+0xF"),
>                      NumberUtils.createNumber("0xF"));
>         try {
>             assertEquals(Integer.decode("+0xF"),
>                          NumberUtils.createNumber("+0xF"));
>             Assertions.fail("This should be possible but it is not");
>         } catch (NumberFormatException ex) {
>             // This should not happen
>         }
>         assertEquals(Long.decode("+0xFFFFFFFF"),
>                      NumberUtils.createNumber("0xFFFFFFFF"));
>         try {
>             assertEquals(Long.decode("+0xFFFFFFFF"),
>                          NumberUtils.createNumber("+0xFFFFFFFF"));
>             Assertions.fail("This should be possible but it is not");
>         } catch (NumberFormatException ex) {
>             // This should not happen
>         }
>         assertEquals(new BigInteger("+FFFFFFFFFFFFFFFF", 16),
>                      NumberUtils.createNumber("0xFFFFFFFFFFFFFFFF"));
>         try {
>             assertEquals(new BigInteger("+FFFFFFFFFFFFFFFF", 16),
>                          NumberUtils.createNumber("+0xFFFFFFFFFFFFFFFF"));
>             Assertions.fail("This should be possible but it is not");
>         } catch (NumberFormatException ex) {
>             // This should not happen
>         }
>     }
> {code}
> A simple fix is to check for a leading '+' character and advance all processing past this character.
>   



--
This message was sent by Atlassian Jira
(v8.3.4#803005)