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

JDK 1.0.2 Double.valueOf() does not complain about invalid strings

XMLWordPrintable

    • 1.1
    • ppc
    • generic
    • Not verified


      It appears as if Double.valueOf( String foo ) uses sscanf or something
      similar that stops on the first invalid byte, rather than an algorithm
      that requires a completely valid string.

      (Note: also seen on MetroWerks and Roaster.)

      import java.awt.*;
      import java.applet.*;

      public class NumberBug extends Applet {
      public void init()
       {
      /*
      * Double incorrectly parses garbage if the string begins
      * with a valid numeric sequence.
      */
      try {
      double value = Double.valueOf("123xyz456.789").doubleValue();
      System.out.println("double 123xyz456.789 parsed as " + value);
      }
      catch (NumberFormatException e) {
      System.out.println("123x456 failed: " + e);
      }
      }
      }


      Output:
      double 123xyz456.789 parsed as 123

            fyellinsunw Frank Yellin (Inactive)
            mchansunw Mei Chan (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: