Example usage for java.lang NullPointerException getMessage

List of usage examples for java.lang NullPointerException getMessage

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:Main.java

/**
 * This method returns the first non-null owner document of the Nodes in this Set.
 * 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 xpathNodeSet// w w w. ja  v a 2s  . c o  m
 * @return the owner document
 */
public static Document getOwnerDocument(Set<Node> xpathNodeSet) {
    NullPointerException npe = null;
    for (Node node : xpathNodeSet) {
        int nodeType = node.getNodeType();
        if (nodeType == Node.DOCUMENT_NODE) {
            return (Document) node;
        }
        try {
            if (nodeType == Node.ATTRIBUTE_NODE) {
                return ((Attr) node).getOwnerElement().getOwnerDocument();
            }
            return node.getOwnerDocument();
        } catch (NullPointerException e) {
            npe = e;
        }
    }

    throw new NullPointerException(npe.getMessage());
}

From source file:org.sakaiproject.util.DbResourceBundle.java

/**
 *
 * @param baseName/*from www  .  ja  v  a2  s  .  c  o  m*/
 * @param locale
 * @param classLoader
 * @return ResourceBundle with values from classpath loading, and overridden by any values
 *         retrieved from the MessageBundleService
 */
static public ResourceBundle addResourceBundle(String baseName, Locale locale, ClassLoader classLoader) {
    DbResourceBundle newBundle = new DbResourceBundle(baseName, locale);
    String context = (String) getThreadLocalManager().get(org.sakaiproject.util.RequestFilter.CURRENT_CONTEXT);
    try {
        if (context != null) {
            Map bundleValues = getMessageBundleService().getBundle(baseName, context, locale);
            Iterator<Entry<String, String>> bundleEntryIter = bundleValues.entrySet().iterator();
            while (bundleEntryIter.hasNext()) {
                Entry<String, String> entry = bundleEntryIter.next();
                String key = entry.getKey();
                String value = entry.getValue();
                newBundle.addProperty(key, value);
            }
        }
        ResourceBundle loadedBundle = null;
        try {
            if (classLoader == null)
                loadedBundle = ResourceBundle.getBundle(baseName, locale);
            else
                loadedBundle = ResourceBundle.getBundle(baseName, locale, classLoader);
        } catch (NullPointerException e) {
        } // ignore

        Enumeration<String> keys = loadedBundle.getKeys();
        while (keys.hasMoreElements()) {
            String key = keys.nextElement();
            if (newBundle.handleGetObject(key) == null) {
                newBundle.addProperty(key, loadedBundle.getString(key));
            }
        }
    } catch (Exception e) {
        log.error(
                "problem loading bundle: " + baseName + " locale: " + locale.toString() + " " + e.getMessage());
    }

    return newBundle;
}

From source file:org.apache.xml.security.utils.XMLUtils.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//from w w w  .j a v a2 s  . c o m
 * @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(
                I18n.translate("endorsed.jdk1.4.0") + " Original message was \"" + npe.getMessage() + "\"");
    }
}

From source file:egovframework.asadal.asapro.com.cmm.util.AsaproEgovStringUtil.java

License:asdf

/**
 * ??? ?   ?17??TIMESTAMP?  /*from  www  . j a  va2s  . c  o  m*/
 *
 * @param
 * @return Timestamp 
 * @exception MyException
 * @see
 */
public static String getTimeStamp() {

    String rtnStr = null;

    // ?    (?--? :::(?? ))
    String pattern = "yyyyMMddhhmmssSSS";

    try {
        SimpleDateFormat sdfCurrent = new SimpleDateFormat(pattern, Locale.KOREA);
        Timestamp ts = new Timestamp(System.currentTimeMillis());

        rtnStr = sdfCurrent.format(ts.getTime());
    } catch (NullPointerException e) {
        log.debug(e.getMessage());
    } catch (IllegalArgumentException e) {
        log.debug(e.getMessage());
    }

    return rtnStr;
}

From source file:pcgen.system.CharacterManager.java

/**
 * Saves this character to the character's file specified
 * by character.getFileRef().getReference()
 * This is expected to be called before a character is to
 * be removed from the list of open characters.
 * @param character the character to be saved
 * @return true if the save succeeded, false if not 
 *//*from   w  w  w .j  a  v  a2 s . c  o  m*/
public static boolean saveCharacter(CharacterFacade character) {
    File file = character.getFileRef().get();
    if (StringUtils.isBlank(file.getName())) {
        return false;
    }

    Logging.log(Logging.INFO, "Saving character " + character.getNameRef().get() //$NON-NLS-1$
            + " - " + file.getAbsolutePath()); //$NON-NLS-1$

    if (character instanceof CharacterFacadeImpl) {
        UIDelegate delegate = character.getUIDelegate();
        try {
            ((CharacterFacadeImpl) character).save();
        } catch (final NullPointerException e) {
            Logging.errorPrint("Could not save " + character.getNameRef().get(), e);
            delegate.showErrorMessage(Constants.APPLICATION_NAME,
                    "Could not save " + character.getNameRef().get());
            return false;
        } catch (final IOException e) {
            Logging.errorPrint("Could not save " + character.getNameRef().get(), e);
            delegate.showErrorMessage(Constants.APPLICATION_NAME,
                    "Could not save " + character.getNameRef().get() + " due to the error:\n" + e.getMessage());
            return false;
        }
    } else {
        Logging.errorPrint("Could not save " + character.getNameRef().get()
                + " due to unexpected class of character: " + character.getClass().getCanonicalName());
        return false;
    }

    RECENT_CHARACTERS.addRecentFile(file);
    return true;
}

From source file:com.github.fge.jsonpatch.mergepatch.NonObjectMergePatchTest.java

@Test
public void patchYellsOnNullInput() throws JsonPatchException {
    try {/* w w  w.j a v a  2  s . com*/
        JsonMergePatch.fromJson(JsonNodeFactory.instance.arrayNode()).apply(null);
        fail("No exception thrown!");
    } catch (NullPointerException e) {
        assertEquals(e.getMessage(), BUNDLE.getMessage("jsonPatch.nullValue"));
    }
}

From source file:org.apache.hadoop.mapred.gridmix.test.system.GridmixJobStory.java

public GridmixJobStory(Path path, Configuration conf) {
    this.path = path;
    this.conf = conf;
    try {/*from   w  w w . j  ava  2 s .  c o  m*/
        zombieJobs = buildJobStories();
        if (zombieJobs == null) {
            throw new NullPointerException("No jobs found in a " + " given trace file.");
        }
    } catch (IOException ioe) {
        LOG.warn("Error:" + ioe.getMessage());
    } catch (NullPointerException npe) {
        LOG.warn("Error:" + npe.getMessage());
    }
}

From source file:com.github.fge.jsonpatch.JsonPatchTest.java

@Test
public void nullInputsDuringBuildAreRejected() throws IOException {
    try {/*w  ww  .jav a  2  s. c om*/
        JsonPatch.fromJson(null);
        fail("No exception thrown!!");
    } catch (NullPointerException e) {
        assertEquals(e.getMessage(), BUNDLE.getMessage("jsonPatch.nullInput"));
    }
}

From source file:org.elasticsearch.client.sniff.HostsSnifferBuilderTests.java

public void testBuild() throws Exception {
    try {//from   w  w w.j  ava2 s. com
        HostsSniffer.builder(null);
        fail("should have failed");
    } catch (NullPointerException e) {
        assertEquals(e.getMessage(), "restClient cannot be null");
    }

    int numNodes = RandomInts.randomIntBetween(getRandom(), 1, 5);
    HttpHost[] hosts = new HttpHost[numNodes];
    for (int i = 0; i < numNodes; i++) {
        hosts[i] = new HttpHost("localhost", 9200 + i);
    }

    try (RestClient client = RestClient.builder(hosts).build()) {
        try {
            HostsSniffer.builder(client).setScheme(null);
            fail("should have failed");
        } catch (NullPointerException e) {
            assertEquals(e.getMessage(), "scheme cannot be null");
        }

        try {
            HostsSniffer.builder(client).setSniffRequestTimeoutMillis(
                    RandomInts.randomIntBetween(getRandom(), Integer.MIN_VALUE, 0));
            fail("should have failed");
        } catch (IllegalArgumentException e) {
            assertEquals(e.getMessage(), "sniffRequestTimeoutMillis must be greater than 0");
        }

        HostsSniffer.Builder builder = HostsSniffer.builder(client);
        if (getRandom().nextBoolean()) {
            builder.setScheme(RandomPicks.randomFrom(getRandom(), HostsSniffer.Scheme.values()));
        }
        if (getRandom().nextBoolean()) {
            builder.setSniffRequestTimeoutMillis(
                    RandomInts.randomIntBetween(getRandom(), 1, Integer.MAX_VALUE));
        }
        assertNotNull(builder.build());
    }
}

From source file:com.github.fge.jsonpatch.JsonPatchTest.java

@Test
public void cannotPatchNull() throws JsonPatchException {
    final JsonPatch patch = new JsonPatch(ImmutableList.of(op1, op2));

    try {/*from  w ww.  ja  va  2s .  c  om*/
        patch.apply(null);
        fail("No exception thrown!!");
    } catch (NullPointerException e) {
        assertEquals(e.getMessage(), BUNDLE.getMessage("jsonPatch.nullInput"));
    }
}