[kaffe] problems with Double.valueOf(String)

Moses DeJong dejong at cs.umn.edu
Wed Jan 6 01:00:44 PST 1999


I just tested the newest kaffe code out of the CVS and I can report
that the problem I was having with Double.valueOf("") has been fixed.
Here is a short example of the current output of kaffe vs jdk1.1.

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

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

mo(/tmp/mo)% kaffe DoubleTest
java.lang.NumberFormatException: empty string
        at DoubleTest.main(6)



Ok, so that works great. Now the only other issues is how the null
object is dealt with in the Double.valueOf() function call. Both
jdk1.1 and jdk1.2 throw a NullPointerException if the null object
is passed into the Double.valueOf() method.



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

mo(/tmp/mo)% /soft/java/JDK-1.1.6/bin/java DoubleTest
java.lang.NullPointerException
        at java.lang.Double.valueOf(Double.java)
        at DoubleTest.main(DoubleTest.java:23)

mo(/tmp/mo)% /tmp/mo/jdk1.2/bin/java DoubleTest
Exception in thread "main" java.lang.NullPointerException
        at java.lang.FloatingDecimal.readJavaFormatString(Compiled Code)
        at java.lang.Double.valueOf(Compiled Code)
        at DoubleTest.main(Compiled Code)

But, kaffe does not!

mo(/tmp/mo)% kaffe DoubleTest
java.lang.NumberFormatException: empty string
        at DoubleTest.main(23)



Kaffe does not raise the same exceptions as the JDK! Kaffe should
raise a NullPointerException not a NumberFormatException when the
null value is passed to the method.





More information about the kaffe mailing list