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

TassertNotNull(T obj)
assert Not Null
if (obj == null) {
    throw new NullPointerException();
return obj;
TassertNotNull(T object, String fieldName)
Asserts that the given object is non-null and returns it.
if (object == null) {
    throw new IllegalArgumentException(String.format("%s cannot be null", fieldName));
return object;
TassertNotNull(T value, String message)
assert Not Null
if (value == null) {
    throw new IllegalArgumentException(message);
return value;
voidassertNotNullArg(Object value, String argName)
assert Not Null Arg
if (value == null)
    throw new IllegalArgumentException(argName + " cannot be null");
voidassertNotNullArgument(Object obj, String argName)
assert Not Null Argument
if (obj == null) {
    throw new IllegalArgumentException("Null Object specified as argument. argumentName[" + argName + "]");
if (obj instanceof String) {
    assertQualifiedString((String) obj, argName);
voidassertNotNullEightBytes(byte[] bytes)
assert Not Null Eight Bytes
if (bytes == null) {
    throw new IllegalArgumentException("Expected 8 bytes, but got null.");
if (bytes.length != 8) {
    throw new IllegalArgumentException(String.format("Expected 8 bytes, but got: %d bytes.", bytes.length));
voidassertNotNullNotEmpty(String obj, String paramName)
assert Not Null Not Empty
assertNotNull(obj, paramName);
if (obj.isEmpty()) {
    throw new IllegalArgumentException(paramName + " cannot be empty");
voidassertNotNullOrThrowException(final Object... objects)
assert Not Null Or Throw Exception
if (!assertNotNull(objects))
    throw new IllegalArgumentException("Cannot be null !");
voidassertObjectNotNull(final Object object)
assert Object Not Null
assert object != null;
voidassertObjectNotNull(Object o, String name)
assert Object Not Null
if (o == null) {
    throw new NullPointerException(name);