I would add to Validate with different names, or adopt an entirely new
approach to constructing exceptions, like that demonstrated in [1].

Matt
[1]
https://github.com/apache/bval/blob/bv2/bval-jsr/src/main/java/org/apache/bval/util/Exceptions.java

On Sun, Oct 7, 2018, 11:13 AM Gary Gregory <garydgreg...@gmail.com> wrote:

> Hi All:
>
> Similar to Objects.requireNonNull() but for IAEs:
>
> /**
>  * Factory methods for {@link IllegalArgumentException}.
>  */
> class IllegalArgumentExceptions {
>
>     private static <T> T requireNonNull(T obj, String message, Object...
> args) {
>         if (obj == null) {
>             throw new IllegalArgumentException(String.format(message,
> args));
>         }
>         return obj;
>     }
>
>     public static <T> T requireNonNull(T obj) {
>         return requireNonNull(obj, "Argument");
>     }
>
>     public static <T> T requireNonNull(T obj, String argumentName) {
>         return requireNonNull(obj, "%s MUST not be null", argumentName);
>     }
>
> }
>
> Suitable for [lang] I would think.
>
> Thoughts?
>
> Gary
>

Reply via email to