Java Assert Not Null assertNotNull(Object object, String description)

Here you can find the source of assertNotNull(Object object, String description)

Description

Throws an NPE if the given object is null that uses the specified text to describe the object.

License

Open Source License

Parameter

Parameter Description
object the text to check
description describes the object, used in the exception message

Exception

Parameter Description
NullPointerException if object is null

Declaration

public static void assertNotNull(Object object, String description) 

Method Source Code

//package com.java2s;

public class Main {
    /**//  ww  w. j  a v a 2  s  . co  m
     * Throws an NPE if the given object is {@code null} that uses
     * the specified text to describe the object.
     *
     * @param object        the text to check
     * @param description   describes the object, used in the exception message
     *
     * @throws NullPointerException if {@code object} is {@code null}
     */
    public static void assertNotNull(Object object, String description) {
        if (object == null) {
            throw new NullPointerException("The " + description + " must not be null.");
        }
    }
}

Related

  1. assertNotNull(Object obj, String msgTemplate, Object... params)
  2. assertNotNull(Object obj, String name)
  3. assertNotNull(Object obj, String name)
  4. assertNotNull(Object object)
  5. assertNotNull(Object object, RuntimeException cause)
  6. assertNotNull(Object object, String message)
  7. assertNotNull(Object object, String message)
  8. assertNotNull(Object object, String message)
  9. assertNotNull(Object object, String param)