Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-5017980

Allow signed positive integer to be parsed instead of a NumerFormatException

XMLWordPrintable

    • b03
    • x86
    • windows_xp
    • Not verified

        Name: gm110360 Date: 03/22/2004


        A DESCRIPTION OF THE REQUEST :
        Integer.parseInt("+12") throws a NumberFormatException while
        Integer.parseInt("-12") return a correct value.


        JUSTIFICATION :
        Please allow the parsing of explicit signed positive integer for getting coherence and better lisibility in the processing of int, otherwise one has to write

        if (stringNumber.charAt(0) == '+') {
               Integer.parseInt(stringNumber.substring(1));
        } else {
              Integer.parseInt(stringNumber);
        }


        This enhancement applies also to Byte, Short and Long

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        Integer.parseInt should return the right value for an explicitly positive signed integer.
        ACTUAL -
        throws NumberFormatException
        (Incident Review ID: 244493)
        ======================================================================
        ###@###.### 10/28/04 00:53 GMT

              darcy Joe Darcy
              gmanwanisunw Girish Manwani (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: