org.apache.logging.log4j.core.util
Class Assert

java.lang.Object
  extended by org.apache.logging.log4j.core.util.Assert

public final class Assert
extends Object

Utility class providing common validation logic.


Method Summary
static
<T> T
requireNonNull(T object, String message)
          Throws a NullPointerException if the specified parameter is null, otherwise returns the specified parameter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

requireNonNull

public static <T> T requireNonNull(T object,
                                   String message)
Throws a NullPointerException if the specified parameter is null, otherwise returns the specified parameter.

On Java 7, just use Objects.requireNonNull(T, String)

Usage:

 // earlier you would write this:
 public SomeConstructor(Object param) {
     if (param == null) {
         throw new NullPointerException("param");
     }
     this.field = param;
 }

 // now you can do the same in one line:
 public SomeConstructor(Object param) {
     this.field = Assert.requireNonNull("param");
 }
 

Type Parameters:
T - the type of the parameter to check and return
Parameters:
object - the parameter to check
message - message to populate the NPE with if necessary
Returns:
the specified parameter
Throws:
NullPointerException - if object is null


Copyright © 1999-2014 Apache Software Foundation. All Rights Reserved.
Apache Logging, Apache Log4j, Log4j, Apache, the Apache feather logo, the Apache Logging project logo, and the Apache Log4j logo are trademarks of The Apache Software Foundation.