Avoiding NullPointerException when parameter is null