Java Utililty Methods Assert Not Null

List of utility methods to do Assert Not Null

Description

The list of methods to do Assert Not Null are organized into topic(s).

Method

voidassertArgNotNull(final String argName, final Object argValue)
assert Arg Not Null
if (argValue == null) {
    throw new IllegalArgumentException("Argument '" + argName + "' cannot be null");
voidassertArgNotNull(T obj, String name)
assert Arg Not Null
if (obj == null) {
    throw new IllegalArgumentException("argument " + name == null ? "" : name + " is null");
TassertArgumentNotNull(T argument, String argumentName)
Throws an IllegalArgumentException if the provided argument is null.
if (argument == null)
    throw new IllegalArgumentException("Argument cannot be null - '" + argumentName + "'");
return argument;
voidassertElementNotNull(Object element, Class elementClass)
assert Element Not Null
if (element == null) {
    throw new IllegalArgumentException(elementClass.getName() + " must be set");
voidassertFieldNotNull(Object fieldValue, String fieldName)
Throws an IllegalArgumentException if the specified field is null.
if (fieldValue == null)
    throw new IllegalArgumentException("Field '" + fieldName + "' cannot be null.");
ObjectassertFormatResultNotNull(Object r)
assert Format Result Not Null
if (r != null) {
    return r;
throw new NullPointerException("TemplateValueFormatter result can't be null");
voidassertInstanceOfNotNull(Object obj, Class expClass)
Checks if the passed object is of the class specified, null values throw an exception
if (obj == null) {
    throw new AssertionError(
            "Checking instanceof but object is null, expecting class: " + expClass.getName());
if (!(expClass.isAssignableFrom(obj.getClass()))) {
    throw new AssertionError(
            "Expected class: " + expClass.getName() + " but object has class: " + obj.getClass().getName());
voidassertNotNull(final Object o, final String message)
assert Not Null
if (o == null)
    throw new NullPointerException(message);
voidassertNotNull(final Object obj, final String msg)
assert Not Null
if (null == obj) {
    throw new IllegalArgumentException(msg);
voidassertNotNull(final Object obj, final String reference)
assert Not Null
if (obj == null) {
    throw new IllegalArgumentException(String
            .format("[Assertion failed error. Expected not null reference %s, but got <NULL>]", reference));