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

Integer.parseInt("21474836490900")); prints bogus number

    XMLWordPrintable

Details

    • 1.1
    • sparc
    • solaris_2.4
    • Not verified

    Description

      wnj reports the following (which I've verified with the JDK beta2):

      class Test {
      public static void main(String argv[]) {
      System.out.println(Integer.parseInt("21474836490900"));
      }
      }

      which prints

      10900


      [Tim, 6/19/96:]

      Here is a little test harness for use when testing Integer.parseInt and Long.parseLong:

      class foo {
          public static void main(String st[]) {
      System.out.println("Tests for ints:");
      tryToPrintInteger("0");
      tryToPrintInteger("123");
      tryToPrintInteger("-123");
      tryToPrintInteger("2147483647");
      tryToPrintInteger("-2147483648");
      // The next should raise exceptions:
      tryToPrintInteger("-");
      // The bug was originally reported against this next one:
      tryToPrintInteger("21474836490900");
         tryToPrintInteger("9223372036854775807");
         tryToPrintInteger("-9223372036854775808");
      tryToPrintInteger("-abc");

      System.out.println("Tests for longs:");
      tryToPrintLong("0");
      tryToPrintLong("123");
      tryToPrintLong("-123");
      tryToPrintLong("2147483647");
      tryToPrintLong("-2147483648");
         tryToPrintLong("21474836490900");
         tryToPrintLong("9223372036854775807");
         tryToPrintLong("-9223372036854775808");
      // The next should raise exceptions:
      tryToPrintLong("-");
         tryToPrintLong("9223372036854775808");
         tryToPrintLong("-9223372036854775809");
         tryToPrintLong("9223372036854775809000");
      tryToPrintLong("abc");
          }

          private static void tryToPrintInteger(String s) {
      try {
      System.out.println(Integer.parseInt(s));
      } catch (NumberFormatException e) {
      System.out.println("Raised exception: " + e.toString());
      }
          }
          private static void tryToPrintLong(String s) {
      try {
      System.out.println(Long.parseLong(s));
      } catch (NumberFormatException e) {
      System.out.println("Raised exception: " + e.toString());
      }
          }

      }

      Attachments

        Activity

          People

            tlindholsunw Timothy Lindholm (Inactive)
            tlindholsunw Timothy Lindholm (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: