Example usage for java.lang NullPointerException getCause

List of usage examples for java.lang NullPointerException getCause

Introduction

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

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:Main.java

public static void main(String args[]) {
    try {/*from  ww  w .jav  a2s  .  co  m*/
        demoproc();
    } catch (NullPointerException e) {
        System.out.println("Caught: " + e);
        System.out.println("Original cause: " + e.getCause());
    }
}

From source file:ChainExcDemo.java

public static void main(String args[]) {
    try {//from w ww .j  a  va2s.c  o m
        demoproc();
    } catch (NullPointerException e) {
        System.out.println("Caught: " + e);

        System.out.println("Original cause: " + e.getCause());
    }
}

From source file:eu.learnpad.simulator.mon.impl.ComplexEventProcessorImpl.java

private KnowledgeBase createKnowledgeBase() {
    try {//from ww  w .ja v  a 2  s .  co  m
        KnowledgeBaseConfiguration config = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
        config.setOption(EventProcessingOption.STREAM);

        /* Using knowledge builder to create a knowledgePackage using provided resources (drl file)
         * after the creation the knowledgePackage contained into the knowledge builder will be putted
         * into the knowledgeBase using the method addKnowledgePackages(knowledgeBuilder.getKnowledgePackages())
         */

        knowledgeBuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();

        byte[] firstRuleToLoadByteArray = Manager
                .ReadTextFromFile(System.getProperty("user.dir") + "/configFiles/startupRule.drl").getBytes();
        Resource drlToLoad = ResourceFactory.newByteArrayResource(firstRuleToLoadByteArray);

        try {
            knowledgeBuilder.add(drlToLoad, ResourceType.DRL);
        } catch (Exception asd) {
            System.out.println(asd.getMessage());
        }

        KnowledgeBuilderErrors errors = knowledgeBuilder.getErrors();
        if (errors.size() > 0) {
            for (KnowledgeBuilderError error : errors) {
                System.err.println(error);
            }
            throw new IllegalArgumentException("Could not parse knowledge.");
        }
        knowledgeBase = KnowledgeBaseFactory.newKnowledgeBase(config);
        knowledgeBase.addKnowledgePackages(knowledgeBuilder.getKnowledgePackages());
        return knowledgeBase;
    } catch (NullPointerException e) {
        System.out.println(e.getMessage());
        System.out.println(e.getCause());
        DebugMessages.print(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(), e.getMessage());
        return null;
    }
}

From source file:it.cnr.isti.labsedc.glimpse.impl.ComplexEventProcessorImpl.java

private KnowledgeBase createKnowledgeBase() {
    try {//w  ww  .  j  a v a  2 s .c om
        KnowledgeBaseConfiguration config = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
        config.setOption(EventProcessingOption.STREAM);

        /* Using knowledge builder to create a knowledgePackage using provided resources (drl file)
         * after the creation the knowledgePackage contained into the knowledge builder will be putted
         * into the knowledgeBase using the method addKnowledgePackages(knowledgeBuilder.getKnowledgePackages())
         */

        knowledgeBuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();

        //Resource drlToLoad = ResourceFactory.newFileResource("startupRule.drl");

        String firstRuleToLoad = "import it.cnr.isti.labsedc.glimpse.event.GlimpseBaseEventAbstract; "
                + "declare GlimpseBaseEventAbstract " + "@role( event ) " + "@timestamp( timeStamp ) " + "end";

        byte[] firstRuleToLoadByteArray = firstRuleToLoad.getBytes();
        Resource drlToLoad = ResourceFactory.newByteArrayResource(firstRuleToLoadByteArray);

        knowledgeBuilder.add(drlToLoad, ResourceType.DRL);

        KnowledgeBuilderErrors errors = knowledgeBuilder.getErrors();
        if (errors.size() > 0) {
            for (KnowledgeBuilderError error : errors) {
                System.err.println(error);
            }
            throw new IllegalArgumentException("Could not parse knowledge.");
        }
        knowledgeBase = KnowledgeBaseFactory.newKnowledgeBase(config);
        knowledgeBase.addKnowledgePackages(knowledgeBuilder.getKnowledgePackages());
        return knowledgeBase;
    } catch (NullPointerException e) {
        System.out.println(e.getMessage());
        System.out.println(e.getCause());
        DebugMessages.print(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(), e.getMessage());
        return null;
    }
}

From source file:com.capitalone.dashboard.datafactory.jira.JiraDataFactoryImplTest.java

/**
 * Test method for/*from  ww  w .jav  a  2s.c o m*/
 * {@link com.capitalone.dashboard.datafactory.jira.JiraDataFactoryImpl#getQueryResponse(java.lang.String)}
 * .
 */
@Ignore
@Test
public void testGetQueryResponse() {
    logger.debug("RUNNING TEST FOR BASIC QUERY RESPONSE");
    jiraDataFactory = new JiraDataFactoryImpl(properties.getProperty("jira.credentials"),
            properties.getProperty("jira.base.url"), properties.getProperty("jira.query.endpoint"));
    jiraDataFactory.buildBasicQuery(query);
    try {
        JSONArray rs = jiraDataFactory.getQueryResponse();

        /*
         * Testing actual JSON for values
         */
        JSONArray dataMainArry = new JSONArray();
        JSONObject dataMainObj = new JSONObject();
        dataMainArry = (JSONArray) rs.get(0);
        dataMainObj = (JSONObject) dataMainArry.get(0);

        logger.info("Basic query response: " + dataMainObj.get("fields").toString());
        // fields
        assertTrue("No valid Number was found", dataMainObj.get("fields").toString().length() >= 1);
    } catch (NullPointerException npe) {
        fail("There was a problem with an object used to connect to Jira during the test\n" + npe.getMessage()
                + " caused by: " + npe.getCause());
    } catch (ArrayIndexOutOfBoundsException aioobe) {
        fail("The object returned from Jira had no JSONObjects in it during the test; try increasing the scope of your test case query and try again\n"
                + aioobe.getMessage() + " caused by: " + aioobe.getCause());
    } catch (IndexOutOfBoundsException ioobe) {
        logger.info("JSON artifact may be empty - re-running test to prove this out...");
        JSONArray rs = jiraDataFactory.getQueryResponse();

        /*
         * Testing actual JSON for values
         */
        String strRs = new String();
        strRs = rs.toString();

        logger.info("Basic query response: " + strRs);
        assertEquals("There was nothing returned from Jira that is consistent with a valid response.", "[[]]",
                strRs);
    } catch (Exception e) {
        fail("There was an unexpected problem while connecting to Jira during the test\n" + e.getMessage()
                + " caused by: " + e.getCause());
    }
}

From source file:com.capitalone.dashboard.datafactory.jira.JiraDataFactoryImplTest.java

/**
 * Test method for/* w w w.j  a va 2s.c o  m*/
 * {@link com.capitalone.dashboard.datafactory.jira.JiraDataFactoryImpl#getPagingQueryResponse()}
 * .
 */
@Ignore
@Test
public void testGetPagingQueryResponse() {
    logger.debug("RUNNING TEST FOR PAGING QUERY RESPONSE");
    jiraDataFactory = new JiraDataFactoryImpl(1, properties.getProperty("jira.credentials"),
            properties.getProperty("jira.base.url"), properties.getProperty("jira.query.endpoint"));
    jiraDataFactory.buildBasicQuery(query);
    jiraDataFactory.buildPagingQuery(0);
    try {
        JSONArray rs = jiraDataFactory.getPagingQueryResponse();

        /*
         * Testing actual JSON for values
         */
        JSONArray dataMainArry = new JSONArray();
        JSONObject dataMainObj = new JSONObject();
        dataMainArry = (JSONArray) rs.get(0);
        dataMainObj = (JSONObject) dataMainArry.get(0);

        logger.info("Paging query response: " + dataMainObj.get("fields").toString());
        // fields
        assertTrue("No valid Number was found", dataMainObj.get("fields").toString().length() >= 1);
    } catch (NullPointerException npe) {
        fail("There was a problem with an object used to connect to Jira during the test:\n" + npe.getMessage()
                + " caused by: " + npe.getCause());
    } catch (ArrayIndexOutOfBoundsException aioobe) {
        fail("The object returned from Jira had no JSONObjects in it during the test; try increasing the scope of your test case query and try again.\n"
                + aioobe.getMessage() + " caused by: " + aioobe.getCause());
    } catch (IndexOutOfBoundsException ioobe) {
        logger.info("JSON artifact may be empty - re-running test to prove this out...");

        JSONArray rs = jiraDataFactory.getPagingQueryResponse();

        /*
         * Testing actual JSON for values
         */
        String strRs = new String();
        strRs = rs.toString();

        logger.info("Paging query response: " + strRs);
        assertEquals("There was nothing returned from Jira that is consistent with a valid response.", "[[]]",
                strRs);
    } catch (Exception e) {
        fail("There was an unexpected problem while connecting to Jira during the test:\n" + e.getMessage()
                + " caused by: " + e.getCause());
    }
}

From source file:com.daro.persistence.generic.dao.GenericDaoImpl.java

/**
 * Get Current Session from Session Factory.
 * //from w ww . j  av a2 s.c om
 * @return Session Session instance
 * @throws PersistenceException
 */
protected Session getCurrentSession() throws PersistenceException {
    Session session = null;

    try {
        session = this.sessionFactory.getCurrentSession();
    } catch (java.lang.NullPointerException nullPpointEx) {
        logger.error("Persistence layer error: " + nullPpointEx.getStackTrace());
        throw new PersistenceException(PersistenceError.SESSION_FACTORY_NULL, nullPpointEx.getCause());
    } catch (Exception ex) {
        logger.error("Persistence layer error: " + ex.getStackTrace());
        PersistenceError error = PersistenceError.PERSISTENCE_INTERNAL_ERROR;
        throw new PersistenceException(error, ex.getCause());
    }

    return session;
}

From source file:com.swordlord.jalapeno.datacontainer.DataContainer.java

/**
 * Persist object context./*from ww w .  j  av a  2  s .  com*/
 * 
 * @param oc the oc
 * 
 * @return true, if successful
 */
private boolean persistObjectContext(ObjectContext oc) {
    try {
        // disabling the context validation should only be used when you know what you do!
        if (getDisableValidation()) {
            DataContext context = (DataContext) oc;
            context.setValidatingObjectsOnCommit(false);
        }
        oc.commitChanges();
    } catch (ValidationException vex) {
        String strMessage = "";

        ValidationResult vr = vex.getValidationResult();
        if (vr.hasFailures()) {
            List<ValidationFailure> failures = vr.getFailures();
            if (failures.size() > 0) {
                Iterator<ValidationFailure> it = failures.iterator();
                while (it.hasNext()) {
                    ValidationFailure failure = it.next();
                    if (failure != null) {
                        addError(failure.getSource().toString(), failure.getDescription());

                        LOG.info(failure.getSource() + " - " + failure.getDescription());
                    }

                    if (failure instanceof BeanValidationFailure) {
                        BeanValidationFailure bvf = (BeanValidationFailure) failure;
                        strMessage += bvf.getSource() + " - " + bvf.getProperty() + " - " + bvf.getDescription()
                                + ".\n\r";
                        LOG.error(bvf.getSource() + " - " + bvf.getProperty() + " - " + bvf.getDescription());
                    }
                }
            }
        }

        String strError = "Persist crashed: " + vex.getMessage() + ": " + vex.getCause() + "\n\r" + strMessage;
        LOG.info(strError);

        strMessage = vex.getLocalizedMessage() + " - " + strMessage;

        Throwable cause = vex.getCause();
        if (cause != null) {
            strMessage += " - " + cause.getMessage();
        }

        addError("", strMessage);

        //ErrorDialog.reportError("validation: " + strMessage);
        return false;
    } catch (DeleteDenyException dde) {
        String strError = "Persist crashed: " + dde.getLocalizedMessage() + ": " + dde.getCause();
        LOG.error(strError);

        String strMessage = dde.getLocalizedMessage();

        addError("", strMessage);

        return false;
    } catch (FaultFailureException ffe) {
        String strError = "Persist crashed: " + ffe.getLocalizedMessage() + ": " + ffe.getCause();
        LOG.error(strError);

        String strMessage = ffe.getLocalizedMessage();

        addError("", strMessage);

        return false;
    } catch (CayenneRuntimeException cex) {
        String strError = "Persist crashed: " + cex.getMessage() + ": " + cex.getCause();
        LOG.error(strError);

        String strMessage = cex.getLocalizedMessage();

        addError("", strMessage);

        return false;
    } catch (NullPointerException e) {
        String strError = "Persist crashed: NullPointerException";
        LOG.error(strError);

        addError("", strError);
        LOG.debug(e.getMessage());

        return false;
    } catch (Exception e) {
        String strError = "Persist crashed: " + e.getLocalizedMessage() + ": " + e.getCause();
        LOG.error(strError);

        String strMessage = e.getLocalizedMessage();

        addError("", strMessage);

        return false;
    }

    return true;
}

From source file:org.catechis.Stats.java

private void addErrorToLog(java.lang.NullPointerException npe) {
    log.add("toString           : " + npe.toString());
    log.add("getMessage         : " + npe.getMessage());
    log.add("getLocalziedMessage:" + npe.getLocalizedMessage());
    Throwable throwup = npe.getCause();
    Throwable init_cause = npe.initCause(throwup);
    log.add("thowable.msg       :" + init_cause.toString());
    StackTraceElement[] ste = npe.getStackTrace();
    for (int j = 0; j < ste.length; j++) {
        log.add(j + " - " + ste[j].toString());
        if (j > 6) {
            log.add("  ...");
            break;
        }/*from   ww w  .  ja v a  2 s  .  com*/
    }
}

From source file:net.tbnr.gearz.game.GearzGame.java

protected final ArrayList<GUIItem> getPlayersForMenu() {
    ArrayList<GUIItem> items = new ArrayList<>();
    try {//from ww w . j a v  a 2 s  .c o  m
        for (PlayerType player : getPlayers()) {
            Gearz.getInstance().debug(
                    "GEARZ DEBUG ---<GearzGame|399>--------< getPlayersForMenu / player loop has been CAUGHT for: "
                            + player.toString());

            if (!player.isValid()) {
                continue;
            }

            ItemStack stack = new ItemStack(Material.SKULL_ITEM, 1, (short) SkullType.PLAYER.ordinal());
            ItemMeta itemMeta = stack.getItemMeta();
            String name = player.getPlayer().getName();
            itemMeta.setDisplayName(getGameMeta().mainColor() + name);
            stack.setItemMeta(itemMeta);
            items.add(new GUIItem(stack, player.getUsername()));
        }
    } catch (NullPointerException npe) {
        Gearz.getInstance().debug(
                "GEARZ DEBUG ---<GearzGame|417>--------< getPlayersForMenu / player loop has thrown a npe: "
                        + npe.getCause());
    } catch (Exception exception) {
        exception.printStackTrace();
    }
    return items;
}