Why do Double.parseDouble(null) and Integer.parseInt(null) throw different exceptions?
Is this a historical accident or intentional? The documentation clearly states two types of exceptions for Double.parseDouble(...)
and one for Integer.parseInt()
, but it seems inconsistent:
Integer.parseInt(null); // throws java.lang.NumberFormatException: null
However
Double.parseDouble(null); // throws java.lang.NullPointerException
Note: everything in this post is in the source of Java7-b147
Double.parseDouble()
goes into a Sun library (insun.misc.FloatingDecimal
) the first important thing that happens is:Integer.parseInt()
is done manually in theInteger
class. The first important thing that happens is:I would guess there are two different authors.
And:
As taken from: Bug Report: Integer.parseInt() and Double.parseDouble() throw different exceptions on null.
Like others have stated: It's likely made by different authors.