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