You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on May 28, 2022. It is now read-only.
It's quite hard to find established guidelines on this aspect. The best I could find is this extract from Effective Java.
Previous version of the guidelines (discussed halfway, but not merged) can be found here (refer to the deleted lines). Those guidelines are a bit hard to follow/enforce.
Perhaps a simpler (to follow/enforce) approach is to mandate argument validation for all public methods? i.e. for all public methods,
Try to minimize restrictions on arguments. Instead of restricting a specific type of argument (e.g. null), implement a reasonable behavior for that argument.
At the start of the method, validate arguments against all restrictions in force. Use suitable type of exceptions (preferably, built-in exceptions) to indicate violations.
Document all restrictions and the corresponding exceptions in the header comment.
That still leaves the question of validating arguments in non-public methods.
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Specify when to (and when not to ) validate method arguments
The text was updated successfully, but these errors were encountered: