If the method is not expected to be called with a null argument, it is fine to throw a NullPointerException (NPE for short), since it is a precondition that input!=null, and the caller should have verified it beforehand.
/** My method.
* @param input the input, must not be null.
*/
void myMethod(MyClass input){
if (input==null) throw new NullPointerException();
//...
}
A common idiom for throwing NPE, without incrementing your program branch count is:
void myMethod(MyClass input){
input.getClass(); //NPE if input is null
//...
}
In some cases, the above check is implicit in the code:
void printLowercase(String input){
System.out.println(input.toLowerCase());
}
Avoid implementing a method that fails silently, because it makes hard to the caller to know whether the method failed. Instead, return boolean.
boolean myMethod(MyClass input){
if (input==null) {
//you may log that the input was null
return false;
}
//...
return true;
}