I have a simple setter method for a property and null is not appropriate for this particular property. I have always been torn in this situation: should I throw an IllegalArgumentException, or a NullPointerException? From the javadocs, both seem appropriate. Is there some kind of an understood standard? Or is this just one of those things that you should do whatever you prefer and both are really correct?
I have a simple setter method for a property and null is not appropriate
Share
It seems like an
IllegalArgumentExceptionis called for if you don’t wantnullto be an allowed value, and theNullPointerExceptionwould be thrown if you were trying to use a variable that turns out to benull.