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

/**
 * Validate a SPDY header value. Does not validate max length.
 *//*w  w w  . jav a 2 s. c  om*/
static void validateHeaderValue(String value) {
    if (value == null) {
        throw new NullPointerException("value");
    }
    for (int i = 0; i < value.length(); i++) {
        char c = value.charAt(i);
        if (c == 0) {
            throw new IllegalArgumentException("value contains null character: " + value);
        }
    }
}

From source file:Main.java

/**
 * @param file//from  ww  w.  j ava2 s .  com
 * @param includeHiddleFiles
 * @param includeFolder
 * @return
 */
public static int getNumFilesInFolder(File file, boolean includeHiddleFiles, boolean includeFolder) {
    if (file == null) {
        throw new NullPointerException("file cannot be null");
    }
    if (!file.exists()) {
        throw new NullPointerException("file does not exist");
    }
    if (file.isFile()) {
        throw new ClassCastException("file is not a directory");
    }
    return getSubfilesNumberInFolder(file, includeHiddleFiles, includeFolder);
}

From source file:Main.java

public static Element findNode(Document document, String nodeName) {
    if (document == null)
        throw new NullPointerException("Document cannot be null!");
    if (nodeName == null)
        throw new NullPointerException("Nodename cannot be null!");
    NodeList nodes = document.getElementsByTagName(nodeName);
    if (nodes == null || nodes.getLength() == 0)
        return null;
    if (nodes.getLength() > 1)
        throw new RuntimeException(nodes.getLength() + " nodes found where only 1 was expected");
    return (Element) nodes.item(0);
}

From source file:Main.java

public static boolean isSymlink(File file) throws IOException {
    if (file == null) {
        throw new NullPointerException("File must not be null");
    }//from   ww w.j  a  va 2s  .c o m
    if (isSystemWindows()) {
        return false;
    }
    File fileInCanonicalDir = null;
    if (file.getParent() == null) {
        fileInCanonicalDir = file;
    } else {
        File canonicalDir = file.getParentFile().getCanonicalFile();
        fileInCanonicalDir = new File(canonicalDir, file.getName());
    }

    return !fileInCanonicalDir.getCanonicalFile().equals(fileInCanonicalDir.getAbsoluteFile());
}

From source file:Main.java

static void checkNotNull(final Object value, final String msg) {
    if (value == null) {
        throw new NullPointerException(msg);
    }//from  www .  j  a  v a 2  s  .c o m
}

From source file:Main.java

/**
 * Join the {@code strings} into one string with {@code delimiter} in 
 * between.// w ww  .j a  v  a 2 s  .  c o m
 * 
 * @param strings the string list to join
 * @param delimiter the delimiter
 * 
 * @return the joined string
 */
public static String join(List<String> strings, String delimiter) {
    if (strings == null) {
        throw new NullPointerException("argument 'strings' cannot be null");
    }
    return join(strings.toArray(new String[strings.size()]), delimiter);
}

From source file:Main.java

public static final byte[] compress(byte[] bytes) {
    if (bytes == null) {
        throw new NullPointerException("byte[] is NULL !");
    }/*from  w w w.j  a v a 2  s  .co  m*/
    ByteArrayOutputStream bos = new ByteArrayOutputStream(8192);
    try {
        GZIPOutputStream gzip = new GZIPOutputStream(bos);
        gzip.write(bytes, 0, bytes.length);
        gzip.finish();
        byte[] fewerBytes = bos.toByteArray();
        gzip.close();
        bos.close();
        gzip = null;
        bos = null;
        return fewerBytes;
    } catch (IOException e) {
        return null;
    }
}

From source file:Main.java

public static Collection<File> listFiles(File directory, String suffix) {
    final String _suffix = "." + suffix;
    FileFilter filter = new FileFilter() {
        @Override/*from  w  w w  .j ava2 s.  c  o  m*/
        public boolean accept(File file) {
            if (file.isDirectory())
                return true;
            String name = file.getName();
            int endLen = _suffix.length();
            if (name.regionMatches(true, name.length() - endLen, _suffix, 0, endLen)) {
                return true;
            }
            return false;
        }
    };
    if (!directory.isDirectory()) {
        throw new IllegalArgumentException("Parameter 'directory' is not a directory");
    }

    if (filter == null) {
        throw new NullPointerException("Parameter 'fileFilter' is null");
    }
    Collection<File> files = new LinkedList<File>();
    innerListFiles(files, directory, filter);
    return files;
}

From source file:Main.java

public static <E> ArrayList<E> arrayAsArrayList(E... elements) {
    if (elements == null) {
        throw new NullPointerException("elements");
    }//  ww w .  j a  v  a  2s  .  c o m
    return new ArrayList<>(Arrays.asList(elements));
}

From source file:Main.java

public static <E> ArrayList<E> asArrayList(E first, E... other) {
    if (other == null) {
        throw new NullPointerException("other");
    }/*w  w w .  j ava 2 s . com*/
    ArrayList<E> list = new ArrayList<>(1 + other.length);
    list.add(first);
    list.addAll(Arrays.asList(other));
    return list;
}