No subject


Tue Jun 22 17:11:04 PDT 2004


public static Double valueOf(String s) throws NumberFormatException

Returns a new Double object initialized to the value represented by the specified
string. The string s is interpreted as the representation of a floating-point value and a
Double object representing that value is created and returned. 

If s is null, then a NullPointerException is thrown. 



So, with this test case in hand I thought I would try my hand at hacking
the kaffe source to fix the problem. After some changes I got this output.

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)% kaffe DoubleTest
java.lang.NullPointerException
        at java/lang/Throwable.<init>(31)
        at java/lang/Exception.<init>(17)
        at java/lang/RuntimeException.<init>(17)
        at java/lang/NullPointerException.<init>(17)
        at java/lang/Double.valueOf(103)
        at DoubleTest.main(23)


So with my changes it seems to work correctly. I do not claim this
is a "good" patch but it should give you guys somewhere to start at
the very least.


diff -r -c copy_kaffe/libraries/clib/native/Double.c kaffe/libraries/clib/native/Double.c
*** copy_kaffe/libraries/clib/native/Double.c	Wed Jan  6 02:11:39 1999
--- kaffe/libraries/clib/native/Double.c	Wed Jan  6 02:29:07 1999
***************
*** 35,43 ****
  }
  
  /*
!  * Convert string to double object.
   */
! double
  java_lang_Double_valueOf0(struct Hjava_lang_String* str)
  {
  	double value;
--- 35,43 ----
  }
  
  /*
!  * Convert string into double object. (JDK 1.0.2)
   */
! struct Hjava_lang_Double*
  java_lang_Double_valueOf0(struct Hjava_lang_String* str)
  {
  	double value;
***************
*** 85,107 ****
  	value = atof(buf);
  #endif
  
! 	return (value);
  
  bail:;
  	SignalError("java.lang.NumberFormatException", msg);
! 	return (0);
  }
  
- /*
-  * Convert string into double class. (JDK 1.0.2)
-  */
- struct Hjava_lang_Double*
- java_lang_Double_valueOf(struct Hjava_lang_String* str)
- {
- 	struct Hjava_lang_Double* obj;
- 	obj = (struct Hjava_lang_Double*)execute_java_constructor("java.lang.Double", 0, "(D)V", java_lang_Double_valueOf0(str));
- 	return (obj);
- }
  
  /*
   * Convert double to jlong.
--- 85,98 ----
  	value = atof(buf);
  #endif
  
!         return (struct Hjava_lang_Double*) execute_java_constructor("java.lang.Double", 0, "(
! D)V", value);
  
  bail:;
  	SignalError("java.lang.NumberFormatException", msg);
! 	return NULL;
  }
  
  
  /*
   * Convert double to jlong.
diff -r -c copy_kaffe/libraries/clib/native/Double.h kaffe/libraries/clib/native/Double.h
*** copy_kaffe/libraries/clib/native/Double.h	Wed Jan  6 02:11:39 1999
--- kaffe/libraries/clib/native/Double.h	Wed Jan  6 02:32:03 1999
***************
*** 21,27 ****
  
  extern jlong java_lang_Double_doubleToLongBits(jdouble);
  extern jdouble java_lang_Double_longBitsToDouble(jlong);
! extern jdouble java_lang_Double_valueOf0(struct Hjava_lang_String*);
  
  #ifdef __cplusplus
  }
--- 21,27 ----
  
  extern jlong java_lang_Double_doubleToLongBits(jdouble);
  extern jdouble java_lang_Double_longBitsToDouble(jlong);
! extern struct Hjava_lang_Double* java_lang_Double_valueOf0(struct Hjava_lang_String*);
  
  #ifdef __cplusplus
  }
diff -r -c copy_kaffe/libraries/javalib/java/lang/Double.java kaffe/libraries/javalib/java/lang/Double.java
*** copy_kaffe/libraries/javalib/java/lang/Double.java	Wed Jan  6 02:11:44 1999
--- kaffe/libraries/javalib/java/lang/Double.java	Wed Jan  6 02:48:08 1999
***************
*** 22,28 ****
    private double value;
  
    public static native String toString(double d);
!   public static native Double valueOf(String s) throws NumberFormatException;
    public static native long doubleToLongBits(double value);
    public static native double longBitsToDouble(long bits);
    
--- 22,28 ----
    private double value;
  
    public static native String toString(double d);
!   static native Double valueOf0(String s) throws NumberFormatException;
    public static native long doubleToLongBits(double value);
    public static native double longBitsToDouble(long bits);
    
***************
*** 44,50 ****
  
    public boolean equals(Object obj) {
      if ( (obj!=null) && (obj instanceof Double)) {
!       Double that=(Double )obj;
        if ((this.isNaN()==true) && (that.isNaN()==true)) return true;
      
        double left, right;
--- 44,50 ----
  
    public boolean equals(Object obj) {
      if ( (obj!=null) && (obj instanceof Double)) {
!       Double that=(Double) obj;
        if ((this.isNaN()==true) && (that.isNaN()==true)) return true;
      
        double left, right;
***************
*** 96,100 ****
--- 96,107 ----
  
    public long longValue() {
      return (long )value;
+   }
+ 
+   public static Double valueOf(String s) throws NumberFormatException {
+     if (s == null) {
+       throw new NullPointerException();
+     }
+     return valueOf0(s);
    }
  }




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



More information about the kaffe mailing list