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:org.openadaptor.auxil.processor.simplerecord.ConditionProcessorTestCase.java

/**
 * Test that what happens when the Then Processor throws a NullPointerException is as expected. <p/> We expect the
 * ConditionProcessor to pass on the NullPointerException.
 *///from  w w  w  . j a v  a2s  .c  o m
public void testThenProcessorThrowsNullPointerException() {
    getAbstractSimpleRecordProcessor().setSimpleRecordAccessor(null);
    expressionMock.expects(once()).method("evaluate").with(eq(record)).will(returnValue(true));
    thenProcessorMock.expects(once()).method("process").with(eq(record))
            .will(throwException(new NullPointerException("NullPointerException thrown by Then Processor")));
    elseProcessorMock.expects(never()).method("process").with(eq(record));
    try {
        testProcessor.process(record);
    } catch (RecordException e) {
        fail("Got RecordException with message: [" + e.getMessage() + "]");
    } catch (NullPointerException npe) {
        log.info("Got NullPointerException with message: [" + npe.getMessage() + "]");
        return; // This is what we expected.
    }
    fail("Expected a RecordException");
}

From source file:org.openadaptor.auxil.processor.simplerecord.ConditionProcessorTestCase.java

/**
 * Test that what happens when the Then Processor throws a NullPointerException is as expected. <p/> We expect the
 * ConditionProcessor to pass on the NullPointerException.
 *//*w w  w .j  a v  a  2  s  .  c o  m*/
public void testElseProcessorThrowsNullPointerException() {
    getAbstractSimpleRecordProcessor().setSimpleRecordAccessor(null);
    expressionMock.expects(once()).method("evaluate").with(eq(record)).will(returnValue(false));
    thenProcessorMock.expects(never()).method("process").with(eq(record));
    elseProcessorMock.expects(once()).method("process").with(eq(record))
            .will(throwException(new NullPointerException("NullPointerException thrown by Else Processor")));
    try {
        testProcessor.process(record);
    } catch (RecordException e) {
        fail("Got RecordException with message: [" + e.getMessage() + "]");
    } catch (NullPointerException npe) {
        log.info("Got NullPointerException with message: [" + npe.getMessage() + "]");
        return; // This is what we expected.
    }
    fail("Expected a NullPointerException");
}

From source file:org.openadaptor.auxil.processor.simplerecord.ConditionProcessorTestCase.java

/**
 * Test that a NullPointerException thrown by an Expression Object is handled properly. <p/> We expect the
 * ConditionProcessor to pass on the NullPointerException.
 *///from  www .  ja v  a  2 s. c o  m
public void testConditionThrowsNullPointerException() {
    getAbstractSimpleRecordProcessor().setSimpleRecordAccessor(null);
    expressionMock.expects(once()).method("evaluate").with(eq(record))
            .will(throwException(new NullPointerException("Thrown by Mock Expression")));
    thenProcessorMock.expects(never()).method("process");
    elseProcessorMock.expects(never()).method("process");
    try {
        testProcessor.process(record);
    } catch (RecordException e) {
        fail("Unexpected RecordException: [" + e + "]");
    } catch (NullPointerException npe) {
        log.info("Got NullPointerException with message: [" + npe.getMessage() + "]");
        return; // This is what we expected.
    }

    fail("Expected a NullPointerException");
}

From source file:org.zaproxy.zap.extension.encoder2.EncodeDecodeDialog.java

private void updateEncodeDecodeFields() {

    // Base 64//from   w w  w .j a v  a  2 s .com
    try {
        base64EncodeField.setText(getEncoder().getBase64Encode(getInputField().getText()));
    } catch (NullPointerException e) {
        log.error(e.getMessage(), e);
    } catch (IOException e) {
        log.error(e.getMessage(), e);
    }

    try {
        base64DecodeField.setText(getEncoder().getBase64Decode(getInputField().getText()));
        base64DecodeField.setEnabled(base64DecodeField.getText().length() > 0);
    } catch (IOException e) {
        base64DecodeField.setText(e.getMessage());
        base64DecodeField.setEnabled(false);
    } catch (IllegalArgumentException e) {
        base64DecodeField.setText(e.getMessage());
        base64DecodeField.setEnabled(false);
    }

    // URLs
    urlEncodeField.setText(getEncoder().getURLEncode(getInputField().getText()));
    try {
        urlDecodeField.setText(getEncoder().getURLDecode(getInputField().getText()));
    } catch (final Exception e) {
        // Not unexpected
        urlDecodeField.setText("");
    }
    urlDecodeField.setEnabled(urlDecodeField.getText().length() > 0);

    // ASCII Hex
    asciiHexEncodeField.setText(getEncoder().getHexString(getInputField().getText().getBytes()));

    try {
        asciiHexDecodeField.setText(decodeHexString(getInputField().getText()));
    } catch (final Exception e) {
        // Not unexpected
        asciiHexDecodeField.setText("");
    }
    asciiHexDecodeField.setEnabled(asciiHexDecodeField.getText().length() > 0);

    // HTML
    HTMLEncodeField.setText(getEncoder().getHTMLString(getInputField().getText()));

    try {
        HTMLDecodeField.setText(decodeHTMLString(getInputField().getText()));
    } catch (final Exception e) {
        // Not unexpected
        HTMLDecodeField.setText("");
    }
    HTMLDecodeField.setEnabled(HTMLDecodeField.getText().length() > 0);

    // JavaScript
    JavaScriptEncodeField.setText(getEncoder().getJavaScriptString(getInputField().getText()));

    try {
        JavaScriptDecodeField.setText(decodeJavaScriptString(getInputField().getText()));
    } catch (final Exception e) {
        // Not unexpected
        JavaScriptDecodeField.setText("");
    }
    JavaScriptDecodeField.setEnabled(JavaScriptDecodeField.getText().length() > 0);

    // Hashes
    try {
        sha1HashField.setText(
                getEncoder().getHexString(getEncoder().getHashSHA1(getInputField().getText().getBytes())));
    } catch (final Exception e) {
        sha1HashField.setText("");
    }

    try {
        md5HashField.setText(
                getEncoder().getHexString(getEncoder().getHashMD5(getInputField().getText().getBytes())));
    } catch (final Exception e) {
        md5HashField.setText("");
    }

    //Illegal UTF8
    try {
        illegalUTF82ByteField.setText(getEncoder().getIllegalUTF8Encode(getInputField().getText(), 2));
    } catch (final Exception e) {
        // Not unexpected
        illegalUTF82ByteField.setText("");
    }

    try {
        illegalUTF83ByteField.setText(getEncoder().getIllegalUTF8Encode(getInputField().getText(), 3));
    } catch (final Exception e) {
        // Not unexpected
        illegalUTF83ByteField.setText("");
    }

    try {
        illegalUTF84ByteField.setText(getEncoder().getIllegalUTF8Encode(getInputField().getText(), 4));
    } catch (final Exception e) {
        // Not unexpected
        illegalUTF84ByteField.setText("");
    }

}

From source file:org.pentaho.di.job.entries.hadooptransjobexecutor.DistributedCacheUtilTest.java

@Test
public void installKettleEnvironment_missing_arguments() throws Exception {
    DistributedCacheUtil ch = new DistributedCacheUtil();

    try {//from  w  w  w .j a  va 2  s.co  m
        ch.installKettleEnvironment(null, null, null, null, null);
        fail("Expected exception on missing archive");
    } catch (NullPointerException ex) {
        assertEquals("pmrArchive is required", ex.getMessage());
    }

    try {
        ch.installKettleEnvironment(KettleVFS.getFileObject("."), null, null, null, null);
        fail("Expected exception on missing archive");
    } catch (NullPointerException ex) {
        assertEquals("destination is required", ex.getMessage());
    }

    try {
        ch.installKettleEnvironment(KettleVFS.getFileObject("."), null, new Path("."), null, null);
        fail("Expected exception on missing archive");
    } catch (NullPointerException ex) {
        assertEquals("big data plugin required", ex.getMessage());
    }
}

From source file:org.apache.unomi.plugins.baseplugin.conditions.PropertyConditionEvaluator.java

@Override
public boolean eval(Condition condition, Item item, Map<String, Object> context,
        ConditionEvaluatorDispatcher dispatcher) {
    String op = (String) condition.getParameter("comparisonOperator");
    String name = (String) condition.getParameter("propertyName");

    String expectedValue = ConditionContextHelper.foldToASCII((String) condition.getParameter("propertyValue"));
    Object expectedValueInteger = condition.getParameter("propertyValueInteger");
    Object expectedValueDate = condition.getParameter("propertyValueDate");
    Object expectedValueDateExpr = condition.getParameter("propertyValueDateExpr");

    Object actualValue;/*from   w ww  .  j a v a 2 s.  c o m*/
    if (item instanceof Event && "eventType".equals(name)) {
        actualValue = ((Event) item).getEventType();
    } else {
        try {
            long time = System.nanoTime();
            //actualValue = beanUtilsBean.getPropertyUtils().getProperty(item, name);
            actualValue = getPropertyValue(item, name);
            time = System.nanoTime() - time;
            if (time > 5000000L) {
                logger.info("eval took {} ms for {} {}", time / 1000000L, item.getClass().getName(), name);
            }
        } catch (NullPointerException e) {
            // property not found
            actualValue = null;
        } catch (Exception e) {
            if (!(e instanceof OgnlException)
                    || (!StringUtils.startsWith(e.getMessage(), "source is null for getProperty(null"))) {
                logger.warn("Error evaluating value for " + item.getClass().getName() + " " + name, e);
            }
            actualValue = null;
        }
    }
    if (actualValue instanceof String) {
        actualValue = ConditionContextHelper.foldToASCII((String) actualValue);
    }

    if (op == null) {
        return false;
    } else if (actualValue == null) {
        return op.equals("missing");
    } else if (op.equals("exists")) {
        return true;
    } else if (op.equals("equals")) {
        if (actualValue instanceof Collection) {
            for (Object o : ((Collection<?>) actualValue)) {
                if (o instanceof String) {
                    o = ConditionContextHelper.foldToASCII((String) o);
                }
                if (compare(o, expectedValue, expectedValueDate, expectedValueInteger,
                        expectedValueDateExpr) == 0) {
                    return true;
                }
            }
            return false;
        }
        return compare(actualValue, expectedValue, expectedValueDate, expectedValueInteger,
                expectedValueDateExpr) == 0;
    } else if (op.equals("notEquals")) {
        return compare(actualValue, expectedValue, expectedValueDate, expectedValueInteger,
                expectedValueDateExpr) != 0;
    } else if (op.equals("greaterThan")) {
        return compare(actualValue, expectedValue, expectedValueDate, expectedValueInteger,
                expectedValueDateExpr) > 0;
    } else if (op.equals("greaterThanOrEqualTo")) {
        return compare(actualValue, expectedValue, expectedValueDate, expectedValueInteger,
                expectedValueDateExpr) >= 0;
    } else if (op.equals("lessThan")) {
        return compare(actualValue, expectedValue, expectedValueDate, expectedValueInteger,
                expectedValueDateExpr) < 0;
    } else if (op.equals("lessThanOrEqualTo")) {
        return compare(actualValue, expectedValue, expectedValueDate, expectedValueInteger,
                expectedValueDateExpr) <= 0;
    } else if (op.equals("between")) {
        List<?> expectedValuesInteger = (List<?>) condition.getParameter("propertyValuesInteger");
        List<?> expectedValuesDate = (List<?>) condition.getParameter("propertyValuesDate");
        List<?> expectedValuesDateExpr = (List<?>) condition.getParameter("propertyValuesDateExpr");
        return compare(actualValue, null,
                (expectedValuesDate != null && expectedValuesDate.size() >= 1)
                        ? getDate(expectedValuesDate.get(0))
                        : null,
                (expectedValuesInteger != null && expectedValuesInteger.size() >= 1)
                        ? (Integer) expectedValuesInteger.get(0)
                        : null,
                (expectedValuesDateExpr != null && expectedValuesDateExpr.size() >= 1)
                        ? (String) expectedValuesDateExpr.get(0)
                        : null) >= 0
                && compare(actualValue, null,
                        (expectedValuesDate != null && expectedValuesDate.size() >= 2)
                                ? getDate(expectedValuesDate.get(1))
                                : null,
                        (expectedValuesInteger != null && expectedValuesInteger.size() >= 2)
                                ? (Integer) expectedValuesInteger.get(1)
                                : null,
                        (expectedValuesDateExpr != null && expectedValuesDateExpr.size() >= 2)
                                ? (String) expectedValuesDateExpr.get(1)
                                : null) <= 0;
    } else if (op.equals("contains")) {
        return actualValue.toString().contains(expectedValue);
    } else if (op.equals("startsWith")) {
        return actualValue.toString().startsWith(expectedValue);
    } else if (op.equals("endsWith")) {
        return actualValue.toString().endsWith(expectedValue);
    } else if (op.equals("matchesRegex")) {
        return expectedValue != null
                && Pattern.compile(expectedValue).matcher(actualValue.toString()).matches();
    } else if (op.equals("in") || op.equals("notIn") || op.equals("all")) {
        List<?> expectedValues = ConditionContextHelper
                .foldToASCII((List<?>) condition.getParameter("propertyValues"));
        List<?> expectedValuesInteger = (List<?>) condition.getParameter("propertyValuesInteger");
        List<?> expectedValuesDate = (List<?>) condition.getParameter("propertyValuesDate");
        List<?> expectedValuesDateExpr = (List<?>) condition.getParameter("propertyValuesDateExpr");

        return compareMultivalue(actualValue, expectedValues, expectedValuesDate, expectedValuesInteger,
                expectedValuesDateExpr, op);
    } else if (op.equals("isDay") && expectedValueDate != null) {
        return yearMonthDayDateFormat.format(getDate(actualValue))
                .equals(yearMonthDayDateFormat.format(getDate(expectedValueDate)));
    } else if (op.equals("isNotDay") && expectedValueDate != null) {
        return !yearMonthDayDateFormat.format(getDate(actualValue))
                .equals(yearMonthDayDateFormat.format(getDate(expectedValueDate)));
    }

    return false;
}

From source file:zack.yovel.clear.controller.foreground.MainActivity.java

private void scheduleProgressDismiss(int expirationDuration) {
    Handler dismissHandler;//w ww .j a  v a2 s .c om
    try {
        dismissHandler = getWindow().getDecorView().getHandler();
    } catch (NullPointerException e) {
        Log.e(TAG, "scheduleProgressDismiss failed with error: " + e.getMessage());
        dismissHandler = handler;
    }

    if (dismissHandler != null) {
        dismissHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                if (progress != null && progress.isShowing()) {
                    progress.dismiss();
                    progress = null;
                    Log.d("test", "scheduleProgressDismiss");
                    getCannotFindLocationDialog().show();
                }
            }
        }, expirationDuration);
    }
}

From source file:org.jetbrains.webdemo.sessions.MyHttpSession.java

private void sendDeleteProjectResult(HttpServletRequest request) {
    try {//from ww w  . j  a  v  a 2s . c  om
        sessionInfo.setType(SessionInfo.TypeOfRequest.DELETE_PROJECT);
        MySqlConnector.getInstance().deleteProject(sessionInfo.getUserInfo(), request.getParameter("publicId"));
        writeResponse(HttpServletResponse.SC_OK);
    } catch (NullPointerException e) {
        writeResponse("Can't get parameters", HttpServletResponse.SC_BAD_REQUEST);
    } catch (DatabaseOperationException e) {
        writeResponse(e.getMessage(), HttpServletResponse.SC_FORBIDDEN);
    }
}

From source file:org.jetbrains.webdemo.sessions.MyHttpSession.java

private void sendExistenceCheckResult() {
    try {/*from   w  ww  .ja  v a  2 s .  c  o  m*/
        String id = request.getParameter("publicId");
        ObjectNode response = new ObjectNode(JsonNodeFactory.instance);
        response.put("exists", MySqlConnector.getInstance().isProjectExists(id));
        writeResponse(response.toString(), HttpServletResponse.SC_OK);
    } catch (NullPointerException e) {
        writeResponse("Can't get parameters", HttpServletResponse.SC_BAD_REQUEST);
    } catch (DatabaseOperationException e) {
        writeResponse(e.getMessage(), HttpServletResponse.SC_BAD_REQUEST);
    }
}

From source file:org.jetbrains.webdemo.sessions.MyHttpSession.java

private void sendAddFileResult() {
    try {/*from  w ww  . ja v  a  2s  .  c  o  m*/
        String projectPublicId = request.getParameter("publicId");
        String fileName = request.getParameter("filename");
        String id = MySqlConnector.getInstance().addFileToProject(sessionInfo.getUserInfo(), projectPublicId,
                fileName);
        writeResponse(id, HttpServletResponse.SC_OK);
    } catch (NullPointerException e) {
        writeResponse("Can't get parameters", HttpServletResponse.SC_BAD_REQUEST);
    } catch (DatabaseOperationException e) {
        writeResponse(e.getMessage(), HttpServletResponse.SC_FORBIDDEN);
    }
}