Example usage for java.lang NullPointerException NullPointerException

List of usage examples for java.lang NullPointerException NullPointerException

Introduction

In this page you can find the example usage for java.lang NullPointerException NullPointerException.

Prototype

public NullPointerException(String s) 

Source Link

Document

Constructs a NullPointerException with the specified detail message.

Usage

From source file:Main.java

/**
 * Get a list of all threads in a thread group. An empty array is returned
 * if there are no threads in the group.
 * /*from  w  ww .  j  a v  a2  s  .  c  o  m*/
 * @param group
 *        the thread group to list
 * @return an array of threads
 * @throws NullPointerException
 *         if the group is null
 */
public static Thread[] getGroupThreads(final ThreadGroup group) {
    if (group == null) {
        throw new NullPointerException("Null group");
    }
    int nAlloc = group.activeCount();
    int n = 0;
    Thread[] threads = null;
    do {
        nAlloc *= 2;
        threads = new Thread[nAlloc];
        n = group.enumerate(threads, false);
    } while (n == nAlloc);
    return java.util.Arrays.copyOf(threads, n);
}

From source file:jef.tools.Assert.java

/**
 * ?null/*from   w  w w  .ja v  a 2 s.  co  m*/
 * @param obj
 */
public static void notNull(Object obj) {
    if (obj == null)
        throw new NullPointerException("The input parameter must not be null!");
}

From source file:Main.java

/**
 * Get the thread group with the given name. A null is returned if no such
 * group is found. If more than one group has the same name, the first one
 * found is returned./*from   w  w  w .ja  v  a  2  s  . c  o  m*/
 * 
 * @param name
 *        the thread group name to search for
 * @return the thread group, or null if not found
 * @throws NullPointerException
 *         if the name is null
 */
public static ThreadGroup getThreadGroup(final String name) {
    if (name == null) {
        throw new NullPointerException("Null name");
    }
    final ThreadGroup[] groups = getAllThreadGroups();
    for (ThreadGroup group : groups) {
        if (group.getName().equals(name))
            return group;
    }
    return null;
}

From source file:com.qait.automation.samjbehavedemo.utils.FileHandler.java

public static List<String> getFileNames(String filedirpath, final String filenameendswith) {

    List<String> filenames = new ArrayList<>();

    File[] files = getFile(filedirpath).listFiles();

    for (File file : files) {
        String filename = file.getName();
        if (file.isFile() && filename.toLowerCase().endsWith(filenameendswith.toLowerCase())) {
            filenames.add(filename);/*  w  ww.  j  ava2 s. co  m*/
        }
    }

    if (filenames.isEmpty()) {
        throw new NullPointerException(
                "There are no files matching the criteria in directoy: " + filedirpath.toUpperCase());
    }

    return filenames;
}

From source file:edu.cornell.mannlib.vitro.webapp.filestorage.TempFileHolder.java

/**
 * Create a {@link TempFileHolder} holding the given {@link FileInfo}, and
 * attach it to the session with the given attribute name.
 * //from  www . ja  va2  s  . c  o m
 * If an attribute with this name already exists, it is replaced.
 */
public static void attach(HttpSession session, String attributeName, FileInfo fileInfo) {
    if (session == null) {
        throw new NullPointerException("session may not be null.");
    }
    if (attributeName == null) {
        throw new NullPointerException("attributeName may not be null.");
    }
    if (fileInfo == null) {
        throw new NullPointerException("fileInfo may not be null.");
    }
    log.debug("attach this file: " + fileInfo);
    session.setAttribute(attributeName, new TempFileHolder(fileInfo));
}

From source file:Main.java

/**
 * Gets all threads if its name matches a regular expression.  For example,
 * using a regex of "main" will execute a case-sensitive match for threads
 * with the exact name of "main".  A regex of ".*main.*" will execute a
 * case sensitive match for threads with "main" anywhere in their name. A
 * regex of "(?i).*main.*" will execute a case insensitive match of any
 * thread that has "main" in its name.// www.j a  v  a 2  s.  co  m
 * @param regex The regular expression to use when matching a threads name.
 *      Same rules apply as String.matches() method.
 * @return An array (will not be null) of all matching threads.  An empty
 *      array will be returned if no threads match.
 */
static public Thread[] getAllThreadsMatching(final String regex) {
    if (regex == null)
        throw new NullPointerException("Null thread name regex");
    final Thread[] threads = getAllThreads();
    ArrayList<Thread> matchingThreads = new ArrayList<Thread>();
    for (Thread thread : threads) {
        if (thread.getName().matches(regex)) {
            matchingThreads.add(thread);
        }
    }
    return matchingThreads.toArray(new Thread[0]);
}

From source file:edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties.java

public static ConfigurationProperties getBean(ServletRequest request) {
    if (request == null) {
        throw new NullPointerException("request may not be null.");
    }/*from  w w w.j  a  v a2s. c om*/
    if (!(request instanceof HttpServletRequest)) {
        throw new IllegalArgumentException("request must be an HttpServletRequest");
    }
    HttpServletRequest httpRequest = (HttpServletRequest) request;
    return getBean(httpRequest.getSession());
}

From source file:Main.java

/**
 * Ensures that an object reference passed as a parameter to the calling
 * method is not null./*  w ww.  jav  a  2s . co m*/
 *
 * @param reference an object reference
 * @param errorMessage the exception message to use if the check fails; will
 *     be converted to a string using {@link String#valueOf(Object)}
 * @return the non-null reference that was validated
 * @throws NullPointerException if {@code reference} is null
 */
public static <T> T checkNotNull(T reference, Object errorMessage) {
    if (reference == null) {
        throw new NullPointerException(String.valueOf(errorMessage));
    }
    return reference;
}

From source file:br.bireme.mlts.utils.Document2JSON.java

public static Map<String, List<Fieldable>> getMap(final Document doc) {
    if (doc == null) {
        throw new NullPointerException("doc");
    }/*from ww  w. j a va  2  s .  c  o  m*/

    final Map<String, List<Fieldable>> ret = new LinkedHashMap<String, List<Fieldable>>();
    final List<Fieldable> fields = doc.getFields();
    for (Fieldable fld : fields) {
        List<Fieldable> lfld = ret.get(fld.name());
        if (lfld == null) {
            lfld = new ArrayList<Fieldable>();
            ret.put(fld.name(), lfld);
        }
        lfld.add(fld);
    }

    return ret;
}

From source file:fr.univlorraine.mondossierweb.utils.PropertyUtils.java

/** Retourne l'url de serveur elasticSearch */
public static String getElasticSearchUrl() {
    String value = System.getProperty("context.param.elasticsearch.url");
    if (!StringUtils.hasText(value))
        throw new NullPointerException("param.elasticsearch.url cannot be null !");
    return value;
}