Uploaded image for project: 'Commons Lang'
  1. Commons Lang
  2. LANG-997

NumberUtil#isNumber() returns false for "012345678" but not for "12345678"

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Not A Problem
    • 3.3.2
    • None
    • lang.math.*
    • None
    • Java 6

    Description

      With commons-lang 3.2.1:

      boolean ret = NumberUtils.isNumber( "012345678901234567" );
      

      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 with:

                 } 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; 
                 }
      

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              juanpablo Juan Pablo Santos Rodríguez
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: