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:se.vgregion.portal.rss.client.beans.FeedEntryBean.java

private Date toDate(String text) {
    try {//from ww  w .ja v a2  s.  c  o  m
        if (text == null) {
            return null;
        }

        return (dateFormat.parse(text));
    } catch (NullPointerException e) {
        LOGGER.warn("Null date text.");
        return null;
    } catch (Exception e) {
        LOGGER.error(e.getMessage(), e);
        return null;
    }
}

From source file:gov.nih.nci.ncicb.tcga.dcc.QCLiveTestDataGeneratorSlowTest.java

/**
 * Tests the {@link QCLiveTestDataGenerator#executeSQLScriptFile(SchemaType, org.springframework.core.io.Resource)} method with
 * a null SQL script file resource./*  w  w w  .j a va 2s. c o  m*/
 */
@Test
public void testExecuteNullSQLScriptFile() throws IOException, SQLException {

    String actualMessage = null;
    try {
        new QCLiveTestDataGenerator().executeSQLScriptFile(SchemaType.LOCAL_DISEASE, null);
    } catch (NullPointerException npe) {
        actualMessage = npe.getMessage();
    }

    // Assert that the correct exception message is thrown
    assertEquals(
            "Cannot execute SQL script file for schema '" + SchemaType.LOCAL_DISEASE + "' and file 'null'.",
            actualMessage);
}

From source file:gov.nih.nci.ncicb.tcga.dcc.QCLiveTestDataGeneratorSlowTest.java

/**
 * Tests the {@link QCLiveTestDataGenerator#executeSQLScriptFile(SchemaType, org.springframework.core.io.Resource)} method with
 * a null schema name./* www . j  a  v a 2s .c  o m*/
 */
@Test
public void testExecuteSQLScriptFileWithNullSchema() throws IOException, SQLException {

    String actualMessage = null;
    try {
        new QCLiveTestDataGenerator().executeSQLScriptFile(null,
                new ClassPathResource("sql/TestSQLScriptFile.sql"));
    } catch (NullPointerException npe) {
        actualMessage = npe.getMessage();
    }

    // Assert that the correct exception message is thrown
    assertEquals(
            "Cannot execute SQL script file for schema 'null' and file 'class path resource [sql/TestSQLScriptFile.sql]'.",
            actualMessage);
}

From source file:io.jenkins.blueocean.blueocean_git_pipeline.GitCacheCloneReadSaveRequest.java

private GitSCMFileSystem getFilesystem() throws IOException, InterruptedException {
    try {//from  ww w  .ja va  2s  .c o m
        return (GitSCMFileSystem) SCMFileSystem.of(gitSource, new SCMHead(sourceBranch));
    } catch (NullPointerException e) {
        // If the repository is totally empty with no commits, it
        // results in a NPE during the SCMFileSystem.of call
        return null;
    } catch (GitException e) {
        // TODO localization?
        if (e.getMessage().contains("Permission denied")) {
            throw new ServiceException.UnauthorizedException("Not authorized", e);
        }
        throw e;
    }
}

From source file:org.apache.usergrid.rest.management.organizations.applications.ApplicationResource.java

@POST
@Path("export")
@Consumes(APPLICATION_JSON)/*from ww  w .j  a  va2 s . c  o  m*/
@RequireOrganizationAccess
public Response exportPostJson(@Context UriInfo ui, Map<String, Object> json,
        @QueryParam("callback") @DefaultValue("") String callback) throws OAuthSystemException {

    OAuthResponse response = null;
    UUID jobUUID = null;
    Map<String, String> uuidRet = new HashMap<String, String>();

    Map<String, Object> properties;
    Map<String, Object> storage_info;

    try {
        if ((properties = (Map<String, Object>) json.get("properties")) == null) {
            throw new NullPointerException("Could not find 'properties'");
        }
        storage_info = (Map<String, Object>) properties.get("storage_info");
        String storage_provider = (String) properties.get("storage_provider");
        if (storage_provider == null) {
            throw new NullPointerException("Could not find field 'storage_provider'");
        }
        if (storage_info == null) {
            throw new NullPointerException("Could not find field 'storage_info'");
        }

        String bucketName = (String) storage_info.get("bucket_location");
        String accessId = (String) storage_info.get("s3_access_id");
        String secretKey = (String) storage_info.get("s3_key");

        if (bucketName == null) {
            throw new NullPointerException("Could not find field 'bucketName'");
        }
        if (accessId == null) {
            throw new NullPointerException("Could not find field 's3_access_id'");
        }
        if (secretKey == null) {
            throw new NullPointerException("Could not find field 's3_key'");
        }

        json.put("organizationId", organization.getUuid());
        //objEx.setOrganizationId( organization.getUuid() );
        json.put("applicationId", applicationId);
        //objEx.setApplicationId( applicationId );

        jobUUID = exportService.schedule(json);
        uuidRet.put("Export Entity", jobUUID.toString());
    } catch (NullPointerException e) {
        return Response.status(SC_BAD_REQUEST).type(JSONPUtils.jsonMediaType(callback))
                .entity(ServiceResource.wrapWithCallback(e.getMessage(), callback)).build();
    } catch (Exception e) {
        //TODO:throw descriptive error message and or include on in the response
        //TODO:fix below, it doesn't work if there is an exception. Make it look like the OauthResponse.
        return Response.status(SC_INTERNAL_SERVER_ERROR).type(JSONPUtils.jsonMediaType(callback))
                .entity(ServiceResource.wrapWithCallback(e.getMessage(), callback)).build();
    }

    return Response.status(SC_ACCEPTED).entity(uuidRet).build();
}

From source file:org.apache.usergrid.rest.management.organizations.applications.ApplicationResource.java

@POST
@Path("collection/{collection_name}/export")
@Consumes(APPLICATION_JSON)/*from  w w w.  j a  v  a  2 s. c o  m*/
@RequireOrganizationAccess
public Response exportPostJson(@Context UriInfo ui, @PathParam("collection_name") String collection_name,
        Map<String, Object> json, @QueryParam("callback") @DefaultValue("") String callback)
        throws OAuthSystemException {

    OAuthResponse response = null;
    UUID jobUUID = null;
    String colExport = collection_name;
    Map<String, String> uuidRet = new HashMap<String, String>();

    Map<String, Object> properties;
    Map<String, Object> storage_info;

    try {
        //checkJsonExportProperties(json);
        if ((properties = (Map<String, Object>) json.get("properties")) == null) {
            throw new NullPointerException("Could not find 'properties'");
        }
        storage_info = (Map<String, Object>) properties.get("storage_info");
        String storage_provider = (String) properties.get("storage_provider");
        if (storage_provider == null) {
            throw new NullPointerException("Could not find field 'storage_provider'");
        }
        if (storage_info == null) {
            throw new NullPointerException("Could not find field 'storage_info'");
        }

        String bucketName = (String) storage_info.get("bucket_location");
        String accessId = (String) storage_info.get("s3_access_id");
        String secretKey = (String) storage_info.get("s3_key");

        if (bucketName == null) {
            throw new NullPointerException("Could not find field 'bucketName'");
        }
        if (accessId == null) {
            throw new NullPointerException("Could not find field 's3_access_id'");
        }
        if (secretKey == null) {
            throw new NullPointerException("Could not find field 's3_key'");
        }
        json.put("organizationId", organization.getUuid());
        json.put("applicationId", applicationId);
        json.put("collectionName", colExport);

        jobUUID = exportService.schedule(json);
        uuidRet.put("Export Entity", jobUUID.toString());
    } catch (NullPointerException e) {
        return Response.status(SC_BAD_REQUEST).type(JSONPUtils.jsonMediaType(callback))
                .entity(ServiceResource.wrapWithCallback(e.getMessage(), callback)).build();
    } catch (Exception e) {
        //TODO:throw descriptive error message and or include on in the response
        //TODO:fix below, it doesn't work if there is an exception. Make it look like the OauthResponse.
        OAuthResponse errorMsg = OAuthResponse.errorResponse(SC_INTERNAL_SERVER_ERROR)
                .setErrorDescription(e.getMessage()).buildJSONMessage();
        return Response.status(errorMsg.getResponseStatus()).type(JSONPUtils.jsonMediaType(callback))
                .entity(ServiceResource.wrapWithCallback(errorMsg.getBody(), callback)).build();
    }

    return Response.status(SC_ACCEPTED).entity(uuidRet).build();
}

From source file:free.yhc.netmbuddy.model.NetLoader.java

public HttpRespContent getHttpContent(Uri uri, boolean source) throws LocalException {
    if (null == mHttpClient) {
        if (DBG)// w  w w .j  a  v a  2 s  .  c om
            P.v("NetLoader Fail to get HttpClient");
        throw new LocalException(Err.UNKNOWN);
    }

    if (!Utils.isNetworkAvailable())
        throw new LocalException(Err.IO_NET);

    String uriString = uri.toString();
    if (source)
        uriString = uriString.replace(uri.getScheme() + "://" + uri.getHost(), "");

    int retry = Policy.NETOWRK_CONN_RETRY;
    while (0 < retry--) {
        try {
            HttpGet httpGet = new HttpGet(uriString);
            HttpHost httpTarget = new HttpHost(uri.getHost());

            if (DBG)
                P.v("executing request: " + httpGet.getRequestLine().toString());
            //logI("uri: " + httpGet.getURI().toString());
            //logI("target: " + httpTarget.getHostName());

            HttpResponse httpResp = mHttpClient.execute(httpTarget, httpGet);
            if (DBG)
                P.v("NetLoader HTTP response status line : " + httpResp.getStatusLine().toString());

            // TODO
            // Need more case-handling-code.
            // Ex. Redirection etc.
            int statusCode = httpResp.getStatusLine().getStatusCode();
            switch (statusCode) {
            case HttpUtils.SC_OK:
            case HttpUtils.SC_NO_CONTENT:
                ;// expected response. let's move forward
                break;

            default:
                // Unexpected response
                if (DBG)
                    P.w("Unexpected Response  status code : " + httpResp.getStatusLine().getStatusCode());
                throw new LocalException(Err.HTTPGET, statusCode);
            }

            InputStream contentStream = null;
            String contentType = null;
            if (HttpUtils.SC_NO_CONTENT == statusCode) {
                ;
            } else {
                HttpEntity httpEntity = httpResp.getEntity();

                if (null == httpEntity) {
                    if (DBG)
                        P.w("Unexpected NULL entity");
                    throw new LocalException(Err.HTTPGET, statusCode);
                }
                contentStream = httpEntity.getContent();
                try {
                    contentType = httpResp.getFirstHeader("Content-Type").getValue().toLowerCase();
                } catch (NullPointerException e) {
                    // Unexpected response data.
                    if (DBG)
                        P.v("NetLoader IOException : " + e.getMessage());
                    throw new LocalException(Err.IO_NET);
                }
            }

            return new HttpRespContent(statusCode, contentStream, contentType);
        } catch (ClientProtocolException e) {
            if (DBG)
                P.v("NetLoader ClientProtocolException : " + e.getMessage());
            throw new LocalException(Err.UNKNOWN);
        } catch (IllegalArgumentException e) {
            if (DBG)
                P.v("Illegal Argument Exception : " + e.getMessage() + "\n" + "URI : " + uriString);
            throw new LocalException(Err.IO_NET);
        } catch (UnknownHostException e) {
            if (DBG)
                P.v("NetLoader UnknownHostException : Maybe timeout?" + e.getMessage());
            if (mUserClose)
                throw new LocalException(Err.INTERRUPTED);

            if (0 >= retry)
                throw new LocalException(Err.IO_NET);

            ; // continue next retry after some time.
            try {
                Thread.sleep(300);
            } catch (InterruptedException ie) {
                throw new LocalException(Err.INTERRUPTED);
            }
            throw new LocalException(Err.IO_NET);
        } catch (IOException e) {
            if (DBG)
                P.v("NetLoader IOException : " + e.getMessage());
            throw new LocalException(Err.IO_NET);
        } catch (IllegalStateException e) {
            if (DBG)
                P.v("NetLoader IllegalStateException : " + e.getMessage());
            throw new LocalException(Err.UNKNOWN);
        }
    }
    eAssert(false);
    return null;
}

From source file:org.energy_home.jemma.javagal.rest.resources.LocalServicesResource.java

@Get
public void processGet() {
    String epString = (String) getRequest().getAttributes().get(Resources.PARAMETER_EP);

    if (epString == null) {

        // GetLocalServices (GET method with /{ep} not present)
        NodeServices services = null;//from   ww  w.j a  v  a2  s  .  c  om
        try {
            proxyGalInterface = getRestManager().getClientObjectKey(-1, getClientInfo().getAddress())
                    .getGatewayInterface();
            services = proxyGalInterface.getLocalServices();
            Detail _det = new Detail();
            _det.setNodeServices(services);
            Info _info = new Info();
            Status _st = new Status();
            _st.setCode((short) GatewayConstants.SUCCESS);
            _info.setStatus(_st);
            _info.setDetail(_det);
            getResponse().setEntity(Util.marshal(_info), MediaType.APPLICATION_XML);
            return;
        } catch (NullPointerException npe) {
            Info info = new Info();
            Status _st = new Status();
            _st.setCode((short) GatewayConstants.GENERAL_ERROR);
            _st.setMessage(npe.getMessage());
            info.setStatus(_st);
            Info.Detail detail = new Info.Detail();
            info.setDetail(detail);
            getResponse().setEntity(Util.marshal(info), MediaType.APPLICATION_XML);
            return;

        } catch (Exception e) {
            Info info = new Info();
            Status _st = new Status();
            _st.setCode((short) GatewayConstants.GENERAL_ERROR);
            _st.setMessage(e.getMessage());
            info.setStatus(_st);
            Info.Detail detail = new Info.Detail();
            info.setDetail(detail);
            getResponse().setEntity(Util.marshal(info), MediaType.APPLICATION_XML);
            return;

        }

    } else {
        Detail _det = new Detail();
        Info _info = new Info();
        Status _st = new Status();
        _st.setCode((short) GatewayConstants.SUCCESS);
        _info.setStatus(_st);
        _det.getValue().add(ResourcePathURIs.WSNCONNECTION);
        _info.setDetail(_det);
        getResponse().setEntity(Util.marshal(_info), MediaType.APPLICATION_XML);

        return;

    }

}

From source file:de.xirp.ui.widgets.panels.LiveChartComposite.java

/**
 * Adds the given value to the chart.//  w  ww .j  a v  a 2 s. c o m
 * 
 * @param key
 *             The key.
 * @param number
 *             The value.
 * @param timestamp 
 *             The time stamp.
 */
private void addValueToChart(final String key, final Number number, final long timestamp) {
    SWTUtil.asyncExec(new Runnable() {

        /* (non-Javadoc)
         * @see java.lang.Runnable#run()
         */
        public void run() {
            if (!isDisposed()) {
                try {
                    keySeriesMap.get(key).addOrUpdate(new Millisecond(new Date(timestamp)),
                            number.doubleValue());
                } catch (NullPointerException e) {
                    logClass.trace("Trace: " + e.getMessage() + Constants.LINE_SEPARATOR, e); //$NON-NLS-1$
                }
            }
        }
    });
}

From source file:org.totschnig.myexpenses.fragment.PlanList.java

@Override
public void onLoaderReset(Loader<Cursor> loader) {
    int id = loader.getId();
    switch (id) {
    case TEMPLATES_CURSOR:
        mTemplatesCursor = null;//from w  ww.ja v  a  2 s.c o m
        mAdapter.setGroupCursor(null);
    case PLANS_CURSOR:
        mPlanTimeInfo = null;
    default:
        int groupPosition = id / 2;
        if (id % 2 == 0) {
            try {
                mAdapter.setChildrenCursor(groupPosition, null);
            } catch (NullPointerException e) {
                Log.w("TAG", "Adapter expired, try again on the next query: " + e.getMessage());
            }
        }
    }
}