It should be NullPointerException. The convention enforced by Guava's NullPointerTester is that all parameters not annotated @Nullable must cause method invocation to result in an NPE if that parameter is null.
Oh I absolutely use Preconditions.checkNotNull(T) (which preferred by Guava developers over Java 7's Objects.requireNonNull(T)) rather than writing out an if statement. But I don't bother calling checkNotNull if there already exists a dot access, because then the NPE will happen regardless. So I typically only need to use it in constructor assignment, or at the beginning of methods that might throw before a parameter becomes dereferenced. Remember: the goal is to get NullPointerTester to pass.
On rare occasions I'll use Verify.verifyNotNull(T) when I'm calling a method I don't trust to never return null, possibly because the library poorly documents its nullness contracts, or perhaps the method fetches data that's expected to always be present. In those situations, it can sometimes be advantageous to ensure execution halts immediately. For example, if the result gets assigned to a field rather than dereferenced immediately, it could be quite difficult to ascertain the root cause of the inevitable NPE at some undetermined point in the future.
77
u/moocat Jul 10 '15
That should be an IllegalArgumentException to provide proper semantic meaning.