Java Assert Null assertNonNull(final T object, final String paramName)

Here you can find the source of assertNonNull(final T object, final String paramName)

Description

Throws NullPointerException with message paramName if object is null.

License

Open Source License

Parameter

Parameter Description
object value to be null-checked
paramName message for the potential NullPointerException

Exception

Parameter Description
NullPointerException if object is null

Return

object

Declaration

public static <T> T assertNonNull(final T object, final String paramName) throws NullPointerException 

Method Source Code

//package com.java2s;
/*/*from www .  j a v a2 s. c  o  m*/
 * Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except
 * in compliance with the License. A copy of the License is located at
 * 
 * http://aws.amazon.com/apache2.0
 * 
 * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations under the License.
 */

public class Main {
    /**
     * Throws {@link NullPointerException} with message {@code paramName} if {@code object} is null.
     *
     * @param object
     *            value to be null-checked
     * @param paramName
     *            message for the potential {@link NullPointerException}
     * @return {@code object}
     * @throws NullPointerException
     *             if {@code object} is null
     */
    public static <T> T assertNonNull(final T object, final String paramName) throws NullPointerException {
        if (object == null) {
            throw new NullPointerException(paramName + " must not be null");
        }
        return object;
    }
}

Related

  1. assertAllAreNull(String messageIfNull, Object... objects)
  2. assertInstance(final Object object, final Class c, final boolean allowNull)
  3. assertIsNull(Object obj)
  4. assertNonNull(String argumentName, Object argument)
  5. assertNoNull(Object object, String paramName)
  6. assertNull(final Object obj, final String msg)
  7. assertNull(final Object value, final String name)