Integer.parseInt() and Double.parseDoube() throw different exceptions on null

XMLWordPrintable

    • Type: Enhancement
    • Resolution: Won't Fix
    • Priority: P3
    • None
    • Affects Version/s: 1.4.1, 7
    • Component/s: core-libs
    • x86
    • windows_2000, windows_xp, windows_7



      Name: nt126004 Date: 12/03/2002


      FULL PRODUCT VERSION :
      java version "1.4.1_01"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-b01)
      Java HotSpot(TM) Client VM (build 1.4.1_01-b01, mixed mode)

      FULL OPERATING SYSTEM VERSION :
      MS Windows 2k

      5.00.2195

      A DESCRIPTION OF THE PROBLEM :
      When passed a null value, Integer.parseInt() throws a NumberFormatException.
      However, Double.parseDouble() and Float.parseFloat() throw NullPointerException
      when passed null.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      I expected to get the same exception (NullPointerException or
      NumberFormatException) in both cases

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class test {
      public static int getInt(String value, int defaultValue) {
              try {
                  return Integer.parseInt(value);
              } catch(Exception nfe) {
      nfe.printStackTrace();
                  return defaultValue;
              }
          }

          public static float getFloat(String value, float defaultValue) {
              try {
                  return Float.parseFloat(value);
              } catch(Exception nfe) {
      nfe.printStackTrace();
                  return defaultValue;
              }
          }

          public static void main(String[] args) {
              System.out.println(getInt(null, -1));
              System.out.println(getFloat(null, -1));
          }
      }
      ---------- END SOURCE ----------
      (Review ID: 178469)
      ======================================================================

            Assignee:
            Joe Darcy
            Reporter:
            Nathanael Thompson (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: