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() 

Source Link

Document

Constructs a NullPointerException with no detail message.

Usage

From source file:Main.java

public static <E> Iterable<E> iterable(final Iterator<E> iterator) {
    if (iterator == null) {
        throw new NullPointerException();
    }/*ww  w. j  av  a2  s  .  c  om*/
    return new Iterable<E>() {
        public Iterator<E> iterator() {
            return iterator;
        }
    };
}

From source file:Main.java

/**
 * Ensures that an object reference passed as a parameter to the calling
 * method is not null./*from  w w w .  j a v a2  s .c om*/
 *
 * @param reference an object reference
 * @return the non-null reference that was validated
 * @throws NullPointerException if {@code reference} is null
 */
public static <T> T checkNotNull(T reference) {
    if (reference == null) {
        throw new NullPointerException();
    }
    return reference;
}

From source file:com.dominion.salud.pedicom.negocio.configuration.DataSourceContextHolder.java

public static void setTargetDataSource(String targetDataSource) {
    if (StringUtils.isBlank(targetDataSource)) {
        throw new NullPointerException();
    }//  w ww.  j a  v  a 2  s.  co m
    contextHolder.put("Bdactual", targetDataSource);
}

From source file:jenkins.uvision.CoverageParser.java

public static TestRun parse(File inFile) throws IOException {
    FileInputStream fileInputStream = null;
    BufferedInputStream bufferedInputStream = null;
    try {//from   w ww  . j a  v a 2  s . co m
        fileInputStream = new FileInputStream(inFile);
        bufferedInputStream = new BufferedInputStream(fileInputStream);
        CoverageParser parser = new CoverageParser();
        TestRun result = parse(bufferedInputStream);
        if (result == null)
            throw new NullPointerException();
        return result;
    } finally {
        try {
            if (bufferedInputStream != null)
                bufferedInputStream.close();
            if (fileInputStream != null)
                fileInputStream.close();
        } catch (IOException e) {
        }
    }
}

From source file:Main.java

private static <T> void checkParam(T param) {
    if (param == null)
        throw new NullPointerException();
}

From source file:Main.java

/**
 * Copy each map entry to a new map but check that each key and value isn't null. Throw
 * a {@code NullPointerException} if it's the case.
 *
 * @param entries entries to copy//from   w w w  .j ava2 s.  c o  m
 * @param <K> type of key
 * @param <V> type of value
 * @return cloned map
 * @throws NullPointerException if a key or value is null
 */
public static <K, V> Map<K, V> copyMapButFailOnNull(Map<? extends K, ? extends V> entries) {
    Map<K, V> entriesToRemap = new HashMap<>(entries.size());
    entries.forEach((k, v) -> {
        // If a key/value is null, throw NPE, nothing gets mutated
        if (k == null || v == null) {
            throw new NullPointerException();
        }
        entriesToRemap.put(k, v);
    });
    return entriesToRemap;
}

From source file:Main.java

public String getSymbol(String currencyCode, Locale locale) {
    if (currencyCode == null || locale == null)
        throw new NullPointerException();

    if (currencyCode.length() != 3)
        throw new IllegalArgumentException("currency code length not 3");

    for (int i = 0; i < 3; i++)
        if (!Character.isUpperCase(currencyCode.charAt(i)))
            throw new IllegalArgumentException("bad currency code");

    if (!locale.equals(locales[0]))
        throw new IllegalArgumentException("unsupported locale");

    if (currencyCode.equals("ERN"))
        return "Nfk";
    else/*  w w  w. jav  a 2s  .c o m*/
        return null;
}

From source file:Main.java

/**
 * Set the drawable to a specific color and return it
 * @param drawableId the int ID of the drawable to change
 * @param colorToSet The color to set it to
 * @return Drawable/*from  www .j  a  v a 2  s  .  c o  m*/
 * @throws NullPointerException, if it fails, throws a null pointer
 */
public static Drawable colorDrawable(int drawableId, int colorToSet, Context context) {
    try {
        Drawable drawable = ContextCompat.getDrawable(context, drawableId);
        drawable.mutate().setColorFilter(colorToSet, PorterDuff.Mode.MULTIPLY);
        return drawable;
    } catch (Exception e) {
        e.printStackTrace();
        throw new NullPointerException();
    }
}

From source file:cc.redberry.core.number.NumberUtils.java

/**
 * Checks that an object is not null.//from  w  w  w . j a v  a 2s. com
 *
 * @param o Object to be checked.
 * @throws NullPointerException if {@code o} is {@code null}.
 */
static void checkNotNull(Object o) throws NullPointerException {
    if (o == null)
        throw new NullPointerException();
}

From source file:jenkins.uvision.CoverageParser.java

public static TestRun parse(InputStream in) throws IOException {
    if (in == null)
        throw new NullPointerException();
    Digester digester = new Digester();
    digester.setClassLoader(CoverageParser.class.getClassLoader());

    digester.addObjectCreate("TestRun", TestRun.class);
    digester.addObjectCreate("TestRun/SuccessfulTests", SuccessfulTests.class);

    digester.addObjectCreate("TestRun/SuccessfulTests/Test", Test.class);
    digester.addBeanPropertySetter("TestRun/SuccessfulTests/Test/File", "file");
    digester.addBeanPropertySetter("TestRun/SuccessfulTests/Test/Name", "name");
    digester.addBeanPropertySetter("TestRun/SuccessfulTests/Test/Coverage", "coverage");
    digester.addBeanPropertySetter("TestRun/SuccessfulTests/Test/Instructions", "instructions");
    digester.addSetProperties("TestRun/SuccessfulTests/Test", "id", "id");
    digester.addSetProperties("TestRun/SuccessfulTests/Test", "duration", "duration");

    digester.addSetNext("TestRun/SuccessfulTests/Test", "addTest");
    digester.addSetNext("TestRun/SuccessfulTests", "addSuccessfullTests");

    digester.addObjectCreate("TestRun/Statistics", Statistics.class);
    digester.addBeanPropertySetter("TestRun/Statistics/Tests", "tests");
    digester.addBeanPropertySetter("TestRun/Statistics/FailuresTotal", "failuresTotal");
    digester.addBeanPropertySetter("TestRun/Statistics/Errors", "errors");
    digester.addBeanPropertySetter("TestRun/Statistics/Ignored", "ignored");
    digester.addBeanPropertySetter("TestRun/Statistics/Failures", "failures");
    digester.addBeanPropertySetter("TestRun/Statistics/Duration", "duration");

    digester.addSetNext("TestRun/Statistics", "addStatistics");
    digester.addSetNext("TestRun/Statistics", "setStatistics");

    try {/* w ww. j a  va2  s .  c o  m*/
        return (TestRun) digester.parse(in);
    } catch (SAXException e) {
        throw new IOException2("Cannot parse coverage results", e);
    }
}