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

Both Integer.decode and Integer.parseInt fail when intger string starts with a +

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 5.0
    • core-libs
    • x86
    • windows_xp

      A DESCRIPTION OF THE REQUEST :
      Each of the following lines of code will fail with a
       NumberFormatException when executed.

         Integer.decode("+10");
         Integer.parseInt("+10");

      JUSTIFICATION :
      Since both the decode and parseInt methods of the Integer class already support a leading minus sign, why not check for and ignore a leading plus sign.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I would expect the following to work:

         Integer.decode("+10");
         Integer.parseInt("+10");
      ACTUAL -
      Both Integer.decode and Integer.parseInt fail with a
      NumberFormatException when the integer string starts with a plus sign.

      ---------- BEGIN SOURCE ----------

               int i = Integer.decode("+10");
               int j = Integer.parseInt("+10");
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      User program has to check for and remoce any leading plus sign.
      ###@###.### 2005-2-25 13:05:47 GMT

            darcy Joe Darcy
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: