[kaffe] bugs in Double.valueOf(String)

Moses DeJong dejong at cs.umn.edu
Sat Dec 26 20:50:56 PST 1998


Kaffe seems to have some problems in the way it handles Double
objects. In this first example a double 1.0 gets printed as 1
be kaffe but the JDK prints 1.0.


public class DoubleTest {
    public static void main(String[] argv) throws Exception {
	String s = "1.0";
	Double d = Double.valueOf(s);
	System.out.println("value is \"" + d + "\"");
    }
}

mo(/tmp/mo)% setenv CLASSPATH .

mo(/tmp/mo)% /soft/java/JDK-1.1.5/bin/java DoubleTest
value is "1.0"

mo(/tmp/mo)% /tmp/mo/install_kaffe/bin/kaffe DoubleTest
value is "1"




This second example shows a bug in the Double.valueOf(String)
method. When an empty string is passed to the Sun's
implementation of Double.valueOf(String) it will raise an
exception. The kaffe implementation incorrectly returns 0.


public class DoubleTest {
    public static void main(String[] argv) throws Exception {
	String s = "";
	Double d = Double.valueOf(s);
	System.out.println("value is \"" + d + "\"");
    }
}

mo(/tmp/mo)% /soft/java/JDK-1.1.5/bin/java DoubleTest
java.lang.NumberFormatException: 
        at java.lang.Double.valueOf(Compiled Code)
        at DoubleTest.main(Compiled Code)

mo(/tmp/mo)% /tmp/mo/install_kaffe/bin/kaffe DoubleTest
value is "0"





There also seems to be a problem with the method when null
is passed to Double.valueOf(String).


public class DoubleTest {
    public static void main(String[] argv) throws Exception {
	String s = null;
	Double d = Double.valueOf(s);
	System.out.println("value is \"" + d + "\"");
    }
}

mo(/tmp/mo)% /soft/java/JDK-1.1.5/bin/java DoubleTest
java.lang.NullPointerException
        at java.lang.Double.valueOf(Compiled Code)
        at DoubleTest.main(Compiled Code)

mo(/tmp/mo)% /tmp/mo/install_kaffe/bin/kaffe DoubleTest
value is "0"




I hope that helps
mo dejong
dejong at cs.umn.edu



More information about the kaffe mailing list