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:com.github.fge.jackson.jsonpointer.JsonPointerTest.java

@Test
public void cannotAppendNullPointer() {
    final JsonPointer foo = null;
    try {// ww w.  jav  a2 s  .  c o m
        JsonPointer.empty().append(foo);
        fail("No exception thrown!!");
    } catch (NullPointerException e) {
        assertEquals(e.getMessage(), BUNDLE.getMessage("nullInput"));
    }
}

From source file:edu.hawaii.soest.hioos.storx.StorXParserTest.java

@Before
public void setUp() {

    // read the sample data from a binary StorX file
    try {//w w  w  . j a  v a 2s  .  com

        // Set up a simple logger that logs to the console
        BasicConfigurator.configure();

        // create a byte buffer from the binary file data
        storXData = this.getClass().getResourceAsStream("/edu/hawaii/soest/kilonalu/ctd/16364020.RAW");
        dataAsByteArray = IOUtils.toByteArray(storXData);
        buffer = ByteBuffer.wrap(dataAsByteArray);

        // create a parser instance and test that it succeeds
        this.parser = new StorXParser();

    } catch (IOException ioe) {
        fail("There was a problem reading the" + " data file.  The error was: " + ioe.getMessage());

    } catch (NullPointerException npe) {
        fail("There was a problem reading the" + " data file.  The error was: " + npe.getMessage());

    }

}

From source file:org.elasticsearch.client.RequestOptionsTests.java

public void testAddHeader() {
    try {/*from w ww.  ja v  a2 s .  c  om*/
        randomBuilder().addHeader(null, randomAsciiLettersOfLengthBetween(3, 10));
        fail("expected failure");
    } catch (NullPointerException e) {
        assertEquals("header name cannot be null", e.getMessage());
    }

    try {
        randomBuilder().addHeader(randomAsciiLettersOfLengthBetween(3, 10), null);
        fail("expected failure");
    } catch (NullPointerException e) {
        assertEquals("header value cannot be null", e.getMessage());
    }

    RequestOptions.Builder builder = RequestOptions.DEFAULT.toBuilder();
    int numHeaders = between(0, 5);
    List<Header> headers = new ArrayList<>();
    for (int i = 0; i < numHeaders; i++) {
        Header header = new RequestOptions.ReqHeader(randomAsciiAlphanumOfLengthBetween(5, 10),
                randomAsciiAlphanumOfLength(3));
        headers.add(header);
        builder.addHeader(header.getName(), header.getValue());
    }
    RequestOptions options = builder.build();
    assertEquals(headers, options.getHeaders());

    try {
        options.getHeaders().add(new RequestOptions.ReqHeader(randomAsciiAlphanumOfLengthBetween(5, 10),
                randomAsciiAlphanumOfLength(3)));
        fail("expected failure");
    } catch (UnsupportedOperationException e) {
        assertNull(e.getMessage());
    }
}

From source file:org.elasticsearch.client.RequestOptionsTests.java

public void testSetHttpAsyncResponseConsumerFactory() {
    try {//from w w  w.  j  a v a 2 s  . c om
        RequestOptions.DEFAULT.toBuilder().setHttpAsyncResponseConsumerFactory(null);
        fail("expected failure");
    } catch (NullPointerException e) {
        assertEquals("httpAsyncResponseConsumerFactory cannot be null", e.getMessage());
    }

    HttpAsyncResponseConsumerFactory factory = mock(HttpAsyncResponseConsumerFactory.class);
    RequestOptions.Builder builder = RequestOptions.DEFAULT.toBuilder();
    builder.setHttpAsyncResponseConsumerFactory(factory);
    RequestOptions options = builder.build();
    assertSame(factory, options.getHttpAsyncResponseConsumerFactory());
}

From source file:org.elasticsearch.client.SyncResponseListenerTests.java

public void testOnSuccessNullResponse() {
    RestClient.SyncResponseListener syncResponseListener = new RestClient.SyncResponseListener(10000);
    try {//  w  w w. j a v a2 s. c  o m
        syncResponseListener.onSuccess(null);
        fail("onSuccess should have failed");
    } catch (NullPointerException e) {
        assertEquals("response must not be null", e.getMessage());
    }
}

From source file:org.elasticsearch.client.SyncResponseListenerTests.java

public void testOnFailureNullException() {
    RestClient.SyncResponseListener syncResponseListener = new RestClient.SyncResponseListener(10000);
    try {//from www  .  j  a  v a  2s .c  o  m
        syncResponseListener.onFailure(null);
        fail("onFailure should have failed");
    } catch (NullPointerException e) {
        assertEquals("exception must not be null", e.getMessage());
    }
}

From source file:com.jmmd.biz.manager.handle.task.impl.TaskManagerHandle.java

/** 
 * @see com.jmmd.biz.manager.handle.task.TaskManager#getTask(java.lang.Integer)
 *//*from  ww  w .j av a 2 s .com*/
@Override
@AspectLogger(value = "?", discover = true)
public TaskBO getTask(Integer taskId) {
    TaskBO taskBO = null;
    try {

        Validate.notNull(taskId, "id?");

        TaskPO taskPO = taskDomain.getTask(taskId);

        Validate.notNull(taskPO, "?(id:" + taskId + ")");

        /*
         * POBO
         */
        taskBO = new TaskBO();
        BeanUtils.copyProperties(taskPO, taskBO);

    } catch (NullPointerException e) {
        if (logger.isErrorEnabled())
            logger.error(e.getMessage());
    } catch (IllegalArgumentException e) {
        if (logger.isErrorEnabled())
            logger.error(e.getMessage());
    } catch (RuntimeException e) {
        if (logger.isErrorEnabled())
            logger.error(e.getMessage());
    }

    return taskBO;
}

From source file:om.edu.squ.squportal.portlet.dps.utility.UserIdUtil.java

/**
* 
* method name  : getUser/* www  .j  a  v a2 s .c om*/
* @param strUserName
* @return
* UserIdUtil
* return type  : User
* 
* purpose      : Get user
*
* Date          :   Jan 9, 2017 12:37:58 PM
*/
public User getUser(String strUserName) {
    User user = new User();
    try {
        if (isStudentId(strUserName.toUpperCase())) {
            user.setUserId(getStudentId(strUserName));
            user.setUserType(Constants.USER_TYPE_STUDENT);
        } else {
            EmpCommon empCommon = new EmpCommon();
            user.setUserId(empCommon.getEmployeeNumber(strUserName));
            user.setUserType(Constants.USER_TYPE_EMPLOYEE);
        }
    } catch (NullPointerException nullEx) {
        logger.error("Error :: No valid user logged in :: ,{}", nullEx.getMessage());
    }
    return user;
}

From source file:org.elasticsearch.client.RestClientBuilderTests.java

public void testSetPathPrefixNull() {
    try {/*  w  w  w .j a  v a 2s .c  o  m*/
        RestClient.builder(new HttpHost("localhost", 9200)).setPathPrefix(null);
        fail("pathPrefix set to null should fail!");
    } catch (final NullPointerException e) {
        assertEquals("pathPrefix must not be null", e.getMessage());
    }
}

From source file:com.neiljbrown.brighttalk.channels.reportingapi.client.spring.SpringApiClientImplTest.java

/**
 * Tests constructor {@link SpringApiClientImpl#SpringApiClientImpl(String, RestTemplate)} in the case where the
 * supplied host name is invalid, because it contains an unsupported character e.g a space.
 *///from  w  w w . j av a2 s  . co m
@Test
public final void testConstructInvalidHostNameNull() {
    try {
        new SpringApiClientImpl(null, new RestTemplate());
        fail("Expected an exception to be thrown.");
    } catch (NullPointerException e) {
        assertTrue("Unexepected exception message [" + e.toString() + "].",
                e.getMessage().matches(".*host name.*null.*"));
    }
}