Name: nt126004 Date: 12/03/2002
FULL PRODUCT VERSION :
java version "1.4.1_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-b01)
Java HotSpot(TM) Client VM (build 1.4.1_01-b01, mixed mode)
FULL OPERATING SYSTEM VERSION :
MS Windows 2k
5.00.2195
A DESCRIPTION OF THE PROBLEM :
When passed a null value, Integer.parseInt() throws a NumberFormatException.
However, Double.parseDouble() and Float.parseFloat() throw NullPointerException
when passed null.
EXPECTED VERSUS ACTUAL BEHAVIOR :
I expected to get the same exception (NullPointerException or
NumberFormatException) in both cases
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public class test {
public static int getInt(String value, int defaultValue) {
try {
return Integer.parseInt(value);
} catch(Exception nfe) {
nfe.printStackTrace();
return defaultValue;
}
}
public static float getFloat(String value, float defaultValue) {
try {
return Float.parseFloat(value);
} catch(Exception nfe) {
nfe.printStackTrace();
return defaultValue;
}
}
public static void main(String[] args) {
System.out.println(getInt(null, -1));
System.out.println(getFloat(null, -1));
}
}
---------- END SOURCE ----------
(Review ID: 178469)
======================================================================
- duplicates
-
JDK-7133658 Make Number classes' parsing behavior consistent
-
- Closed
-
- relates to
-
JDK-6463998 Undocumented NullPointerException from Float.parseFloat and Double.parseDouble
-
- Resolved
-
-
JDK-4994234 Inconsistencies in parseXXX() Parameter Handling
-
- Closed
-
-
JDK-4417678 valueOf() throws inconsistent set of RuntimeExceptions thoughout java API
-
- Closed
-
-
JDK-8264745 Unify ParseLong Methods to Throw NPE
-
- Closed
-