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

voidassertObjectNotNull(String variableName, Object value)
assert Object Not Null
if (variableName == null) {
    String msg = "The value should not be null: variableName=null value=" + value;
    throw new IllegalArgumentException(msg);
if (value == null) {
    String msg = "The value should not be null: variableName=" + variableName;
    throw new IllegalArgumentException(msg);
voidassertObjectNotNull(String variableName, Object value)
Assert that the object is not null.
if (variableName == null) {
    String msg = "The value should not be null: variableName=null value=" + value;
    throw new IllegalArgumentException(msg);
if (value == null) {
    String msg = "The value should not be null: variableName=" + variableName;
    throw new IllegalArgumentException(msg);
voidassertParameterNotNull(Object parameterValue, String errorMessage)

Asserts that the specified parameter value is not null and if it is, throws an IllegalArgumentException with the specified error message.

if (parameterValue == null) {
    throw new IllegalArgumentException(errorMessage);
voidassertParamNotNull(Object check, String paramName)
assert Param Not Null
if (check == null) {
    throw new IllegalArgumentException(paramName + " is null");
voidassertParamNotNull(String param, String paramName)
Parameter validation.
if (param == null || param.isEmpty()) {
    throw new IllegalArgumentException("Missing Parameter '" + paramName + "' must not be null nor empty");
voidassertPatternNotNull(String methodName, String pattern)
assert Pattern Not Null
if (pattern == null) {
    String msg = "The argument 'pattern' should not be null: method=" + methodName;
    throw new IllegalArgumentException(msg);
voidassertResourceNotNull(String resourcePath, Object resourceHandle)
assert Resource Not Null
if (resourceHandle == null) {
    throw new IllegalArgumentException("Could not find the classpath resource at: " + resourcePath + ".");
voidassertStringNotNullAndNotTrimmedEmpty(String variableName, String value)
Assert that the entity is not null and not trimmed empty.
assertObjectNotNull("variableName", variableName);
assertObjectNotNull("value", value);
if (value.trim().length() == 0) {
    String msg = "The value should not be empty: variableName=" + variableName + " value=" + value;
    throw new IllegalArgumentException(msg);
voidassertStringNotNullNorEmpty(String str, String name)
Check if the given string is null or empty (trimmed).
assertObjectNotNull(str, name);
if (str.trim().length() == 0) {
    throw new IllegalArgumentException(name + " should not be empty (trimmed).");
voidassertStringNotNullOrEmpty(String str, String name)

Check if the string is null or empty.

assertObjectNotNull(str, name);
if (str.trim().length() == 0) {
    throw new IllegalArgumentException(name + " must not be empty.");