Java Assert Not Null assertNotNull(final T value, final String param)

Here you can find the source of assertNotNull(final T value, final String param)

Description

This method verifies if the input argument is null or not.

License

Open Source License

Parameter

Parameter Description
value the value to check
param the name of the attribute storing the value to check

Exception

Parameter Description
IllegalArgumentException an exception

Declaration

public static <T> void assertNotNull(final T value, final String param) throws IllegalArgumentException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//w  w  w.  ja  v a  2  s . com
     * This constant {@link String} represents the error message to use then an {@link IllegalArgumentException}
     * is thrown because the assert on <code>null</code> value check fails. 
     */
    private static final String ILLEGAL_ARGUMENT_EXCEPTION_MSG = "the paramter cannot be null: ";

    /**
     * This method verifies if the input argument is <code>null</code> or not.
     * If it's <code>null</code> an {@link IllegalArgumentException} is thrown.
     * 
     * @param value the value to check
     * @param param the name of the attribute storing the value to check
     * 
     * @throws IllegalArgumentException
     */
    public static <T> void assertNotNull(final T value, final String param) throws IllegalArgumentException {
        if (null == value) {
            throw new IllegalArgumentException(
                    ILLEGAL_ARGUMENT_EXCEPTION_MSG + ((null != param) ? param : "unknown"));
        }
    }
}

Related

  1. assertNotNull(final String message, final Object obj)
  2. assertNotNull(final String message, final Object object)
  3. assertNotNull(final String name, final T object)
  4. assertNotNull(final String param, final Object value)
  5. assertNotNull(final T object, final String message)
  6. assertNotNull(Object argumentThatMustNotBeNull, String argumentName)
  7. assertNotNull(Object expression)
  8. assertNotNull(Object o)
  9. assertNotNull(Object obj)