This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

NumberFormatException incorrectly generated


A NumberFormatException is incorrectly generated in each of
the following four cases:

   Float.parseFloat( "0.1f" );
   Float.parseFloat( "0.1d" );
   Double.parseDouble( "0.1f" );
   Double.parseDouble( "0.1d" );

Here's a possible fix:

2002-04-13  Adam King <aking@dreammechanics.com>

    * java/lang/natDouble.cc (parseDouble): Allow a number to end 
      with the f/F/d/D modifiers.


Index: natDouble.cc
===================================================================
RCS file: /cvsroot/gcc/gcc/libjava/java/lang/natDouble.cc,v
retrieving revision 1.15
diff -u -r1.15 natDouble.cc
--- natDouble.cc	20 Oct 2001 06:26:45 -0000	1.15
+++ natDouble.cc	13 Apr 2002 20:58:28 -0000
@@ -169,6 +169,17 @@
 	 && Character::isWhitespace(str->charAt(start)))
     start++, length--;
 
+  // The String could end with a f/F/d/D which is valid but we don't need.
+  if (length > 0 && Character::isLetter (str->charAt (length-1)))
+    {
+      if (str->charAt (length-1) == 'f' || str->charAt (length-1) == 'F' 
+         || str->charAt (length-1) == 'd' || str->charAt (length-1) == 'D')
+           length--;
+      else
+        // If it's any other letter, it must be invalid.
+        throw new NumberFormatException;
+    }
+
   if (length > 0)
     {
       // Note that UTF can expand 3x.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]