You're right: It's inconsistent. Move along, nothing to see here... ;-) The JDK library is very large, has grown over time, and has various inconsistencies. I have to admit this one surprised me enough that I felt the need to double-check your assertion and the actual behavior (in case it differed from the doc): http://ideone.com/18W8W8) But there we go.
As JB points out, one clue to underlying cause of the inconsistency might be that Integer.parseInt
was in the JDK from the beginning, but Double.parseDouble
was added in 1.2. So perhaps thinking around being more specific about the issue changed between those two times.
SO won't let me post the answer with the link above without code, so:
try {
Integer.parseInt(null); // throws java.lang.NumberFormatException: null
}
catch (Exception e) {
System.out.println("Integer: " + e.getClass().getName());
}
try {
Double.parseDouble(null); // throws java.lang.NullPointerException
}
catch (Exception e) {
System.out.println("Double: " + e.getClass().getName());
}
Output:
Integer: java.lang.NumberFormatException
Double: java.lang.NullPointerException