It's confusing: We all know the words from Doug Lea: "Null sucks". He is right.
Now I there are some approaches to throw exceptions by using googles guava. But what would be the right way now?
1) throwing an NullPointerException
private void foo(Object arg) {
Preconditions.checkNotNull(arg, "arg 'null' not accepted");
}
2) or an IllegalArgumentException
private void foo(Object arg) {
Preconditions.checkArgument(arg!=null, "arg 'null' not accepted");
}
3) or a VerifyException
private void foo(Object arg) {
Verify.verify(arg!=null, "arg 'null' not accepted");
}
I mean, isn't the first approach obsolete cause we don't have a NullPointer access at this time? And why this new third approach.
Could someone lift the fog?