Name: gm110360 Date: 09/10/2003
FULL PRODUCT VERSION :
java version "1.4.2_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_01-b06)
Java HotSpot(TM) Client VM (build 1.4.2_01-b06, mixed mode)
FULL OS VERSION :
Windows 2000/XP proffessional and Linux
A DESCRIPTION OF THE PROBLEM :
The behaviour of Long.parseLong(),Integer.parseInt() is different from Double.parseDouble() and Float.parseFloat(). If initial or trailing spaces are present in the string then the NumberFormatException is thrown. An Example and the corrosponding erroe is given below
public class TestLong
{
public static void main(String args[]) throws Exception
{
double d = Double.parseDouble(" 34 ");
System.out.println("double ="+d);
float f = Float.parseFloat(" 34 ");
System.out.println("float ="+f);
long l = Long.parseLong(" 34 ");
System.out.println("long ="+l);
int i = Integer.parseInt(" 34 ");
System.out.println("int ="+i);
}
}
The Exception thrown is..
Exception in thread "main" java.lang.NumberFormatException: For input string: "
34 "
at java.lang.NumberFormatException.forInputString(NumberFormatException.
java:48)
at java.lang.Long.parseLong(Long.java:323)
at java.lang.Long.parseLong(Long.java:381)
at TestLong.main(TestLong.java:12)
REPRODUCIBILITY :
This bug can be reproduced always.
(Incident Review ID: 188565)
======================================================================