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

/**
 * Converts a class name to a JLS style class name.
 *
 * @param className  the class name/* ww  w .  j ava2 s .  c  o m*/
 * @return the converted name
 */
private static String toCanonicalName(String className) {
    className = deleteWhitespace(className);
    if (className == null) {
        throw new NullPointerException("className must not be null.");
    } else if (className.endsWith("[]")) {
        StringBuilder classNameBuffer = new StringBuilder();
        while (className.endsWith("[]")) {
            className = className.substring(0, className.length() - 2);
            classNameBuffer.append("[");
        }
        String abbreviation = abbreviationMap.get(className);
        if (abbreviation != null) {
            classNameBuffer.append(abbreviation);
        } else {
            classNameBuffer.append("L").append(className).append(";");
        }
        className = classNameBuffer.toString();
    }
    return className;
}

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

public static String getString(final Document doc) {
    if (doc == null) {
        throw new NullPointerException("doc");
    }// w ww . j av  a2s.c  o m
    return getJSON(getMap(doc)).toJSONString();
}

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.
 *
 * @param   group   the thread group to list
 * @return      an array of threads//from w w  w .  jav a2 s . c om
 * @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 threads.clone();
}

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.
 *
 * @param   group   the thread group to list
 * @return      an array of threads/*from   ww  w  .  ja  v a  2  s  . c  om*/
 * @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:Main.java

/**
 * Reads exactly 'byteCount' bytes from 'in' (into 'dst' at offset 'offset'), and throws
 * EOFException if insufficient bytes are available.
 *
 * Used to implement {@link java.io.DataInputStream#readFully(byte[], int, int)}.
 *///  w  w w .ja  v  a2  s .c  o m
public static void readFully(InputStream in, byte[] dst, int offset, int byteCount) throws IOException {
    if (byteCount == 0) {
        return;
    }
    if (in == null) {
        throw new NullPointerException("in == null");
    }
    if (dst == null) {
        throw new NullPointerException("dst == null");
    }
    checkOffsetAndCount(dst.length, offset, byteCount);
    while (byteCount > 0) {
        int bytesRead = in.read(dst, offset, byteCount);
        if (bytesRead < 0) {
            throw new EOFException();
        }
        offset += bytesRead;
        byteCount -= bytesRead;
    }
}

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

/**
 * If this Individual has a main image and a thumbnail, return their info.
 * Otherwise, return null./*from w  w  w . ja v a 2s .co m*/
 */
public static ImageInfo instanceFromEntityUri(WebappDaoFactory webappDaoFactory, Individual entity) {
    if (webappDaoFactory == null) {
        throw new NullPointerException("webappDaoFactory may not be null.");
    }

    if (entity == null) {
        return null;
    }

    IndividualDao individualDao = webappDaoFactory.getIndividualDao();

    String mainImageUri = entity.getMainImageUri();
    if (mainImageUri == null) {
        log.debug("Entity '" + entity.getURI() + "' had no associated main image.");
        return null;
    } else {
        log.debug("Entity '" + entity.getURI() + "' had associated main image: '" + mainImageUri + "'");
    }

    Individual mainFile = individualDao.getIndividualByURI(mainImageUri);
    if (mainFile == null) {
        log.error("Entity '" + entity.getURI() + "' has a main image URI that does not refer to an "
                + "individual: mainImageURI=" + mainImageUri);
        return null;
    }

    Individual thumbFile = mainFile.getRelatedIndividual(VitroVocabulary.FS_THUMBNAIL_IMAGE);
    if (thumbFile == null) {
        log.warn("Main image file '" + mainImageUri + "' had no associated thumbnail.");
        return null;
    } else {
        log.debug("Main image file '" + mainImageUri + "' had associated thumbnail: '" + thumbFile.getURI()
                + "'");
    }

    FileInfo mainInfo = FileInfo.instanceFromSurrogateUri(webappDaoFactory, mainFile.getURI());
    if (mainInfo == null) {
        log.error("Entity '" + entity.getURI() + "' has a mainImage that is not a File "
                + "surrogate: mainImageURI=" + mainImageUri);
        return null;
    }

    FileInfo thumbInfo = FileInfo.instanceFromSurrogateUri(webappDaoFactory, thumbFile.getURI());
    if (thumbInfo == null) {
        log.error("Entity '" + entity.getURI() + "' has a mainImage with a thumbnail that is not a File "
                + "surrogate: mainImageURI=" + mainImageUri + ", thumbnailURI=" + thumbFile.getURI());
        return null;
    }

    return new ImageInfo(mainInfo, thumbInfo);
}

From source file:Main.java

/**
 * This method returns the owner document of a particular node.
 * This method is necessary because it <I>always</I> returns a
 * {@link Document}. {@link Node#getOwnerDocument} returns <CODE>null</CODE>
 * if the {@link Node} is a {@link Document}.
 *
 * @param node//w  w  w  .  j  a va 2 s .com
 * @return the owner document of the node
 */
public static Document getOwnerDocument(Node node) {
    if (node.getNodeType() == Node.DOCUMENT_NODE) {
        return (Document) node;
    }
    try {
        return node.getOwnerDocument();
    } catch (NullPointerException npe) {
        throw new NullPointerException(npe.getMessage());
    }
}

From source file:com.github.wnameless.factorextractor.FactorExtractor.java

/**
 * Returns a Map{@literal <String, Object>} which is extracted from annotated
 * methods of input objects.//from  w  w w .j a v a2s.co  m
 * 
 * @param objects
 *          an array of objects
 * @return a Map{@literal <String, Object>}
 */
public static Map<String, Object> extract(Object... objects) {
    for (Object o : objects) {
        if (o == null)
            throw new NullPointerException("Null object is not allowed");
    }

    Map<String, Object> factors = new HashMap<String, Object>();
    for (Object o : objects) {
        Class<?> testClass = o.getClass();
        for (Method m : testClass.getMethods()) {
            Factor factor = AnnotationUtils.findAnnotation(m, Factor.class);
            if (factor != null) {
                try {
                    factors.put(factor.value(), m.invoke(o));
                } catch (InvocationTargetException wrappedExc) {
                    Throwable exc = wrappedExc.getCause();
                    Logger.getLogger(FactorExtractor.class.getName()).log(Level.SEVERE, m + " failed: " + exc,
                            wrappedExc);
                } catch (Exception exc) {
                    Logger.getLogger(FactorExtractor.class.getName()).log(Level.SEVERE,
                            "INVALID @Factor: " + m + exc, exc);
                }
            }
        }
    }

    return factors;
}

From source file:com.nabla.wapp.server.general.Assert.java

/**
 * Test if object is not null//from w  ww  .j ava  2s. c o  m
 * @param ref - object to test
 * @param message - exception message
 * @throws NullPointerException if object is null
 */
public static <T> void notNull(final T ref, final String message) throws NullPointerException {
    if (log.isDebugEnabled()) {
        if (ref == null)
            throw new NullPointerException(message);
    }
}

From source file:org.bigmouth.nvwa.network.http.utils.HttpUtils.java

public static HttpResponse post(HttpRequest request) throws UnexpectStatusCodeException, HttpException {
    if (null == request) {
        throw new NullPointerException("request");
    }// ww w.java 2s .  c  om
    request.setMethod(Method.POST);
    return access(request);
}