Running FindBug I got an alert on the following code:
public select(List<T> elements) {
if (elements == null)
throw new NullPointerException();
With the following explanation:
Avoid throwing a NullPointerException - it's confusing because most people will assume that the virtual machine threw it. Consider using an IllegalArgumentException instead; this will be clearly seen as a programmer-initiated exception.
However, I always thought throwing null pointer exceptions for null parameters was correct. And I look for example at the implementation of ArrayList, I can find something similar:
public boolean tryAdvance(Consumer<? super E> action) {
if (action == null)
throw new NullPointerException();
So, is it really incorrect? And why? Why is Findbug telling me that is wrong?