Open GoogleCodeExporter opened 9 years ago
Passing null to Guice.createInjector is a programming error. NPE is the right
exception.
Original comment by limpbizkit
on 15 Oct 2008 at 1:31
The primary issue I have with NPE as apposed to IllegalArgumentException is that
though the null dereference is an error, the fact that it's a few layers deep
in the
stack trace violates the "fail fast" principle. IllegalArgumentException is also
indicative of a programming error, and more informative.
Original comment by kris.nuttycombe
on 15 Oct 2008 at 3:59
I note also that the Javadoc makes no reference to the fact that null arguments
are
not valid.
Original comment by kris.nuttycombe
on 15 Oct 2008 at 4:04
FYI, all of the methods in Guice throw NullPointerException given null
arguments unless null is explicitly
permitted.
There have been many IllegalStateException vs. NullPointerException flamewars.
We've decided NPE is the best
choice, if only because it's a lot easier to enforce - just dereference the
parameter.
In any case, the distinction is insignificant. Both exceptions indicate a
programming error, and it is a a mistake
to catch either exception explicitly. (Catching RuntimeException is okay for
fault-tolerance)
Original comment by limpbizkit
on 15 Oct 2008 at 5:52
Original issue reported on code.google.com by
kris.nuttycombe
on 14 Oct 2008 at 11:56