Java Utililty Methods Assert Null

List of utility methods to do Assert Null

Description

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

Method

voidassertAllAreNull(String messageIfNull, Object... objects)
Asserts that all of the objects are null.
for (final Object object : objects) {
    if (object != null) {
        throw new IllegalArgumentException(messageIfNull);
voidassertInstance(final Object object, final Class c, final boolean allowNull)
Asserts the the given object is an instance of the given class -- optionally allowing the object to be null.
if (object == null && allowNull) {
    return;
if (object == null || c == null) {
    throw new NullPointerException();
} else if (!c.isInstance(object)) {
    throw new IllegalArgumentException();
voidassertIsNull(Object obj)
Asserts that the passed entry is null
if (obj != null) {
    throw new AssertionError(
            "Passed object: " + obj.getClass().getName() + " is not null while this was expected");
TassertNonNull(final T object, final String paramName)
Throws NullPointerException with message paramName if object is null.
if (object == null) {
    throw new NullPointerException(paramName + " must not be null");
return object;
voidassertNonNull(String argumentName, Object argument)
assert Non Null
if (argument == null)
    throw new IllegalArgumentException("Argument '" + argumentName + "' is null.");
voidassertNoNull(Object object, String paramName)
Assert that the given object parameter is not null.
if (object == null) {
    throw new NullPointerException(paramName + " cannot be null.");
voidassertNull(final Object obj, final String msg)
assert Null
if (null != obj) {
    throw new IllegalArgumentException(msg);
voidassertNull(final Object value, final String name)
Asserts that the parameter's value is null.
if (value != null) {
    throw new IllegalArgumentException(PREFIX + name + " is not null.");
voidassertNull(Object o)
assert Null
if (o != null) {
    throw new AssertionError("Not null.");
voidassertNull(Object obj)
assert Null
if (obj != null) {
    throw new IllegalArgumentException();