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:it.cnr.isti.labsedc.glimpse.impl.ComplexEventProcessorImpl.java

private KnowledgeBase createKnowledgeBase() {
    try {//from ww w.  jav  a2 s .  com
        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:org.xmlactions.mapping.bean_to_xml.MapperAttribute.java

public Element buildXml(BeanToXml beanToXml, Element parent, Object mapClasses) {
    try {/*ww  w.ja  v  a2 s  .  c om*/
        Object property = PropertyUtils.getSimpleProperty(mapClasses, getProperty());
        Object populatorObject = getPopulator(beanToXml);
        if (populatorObject != null) {
            if (populatorObject instanceof Populator) {
                Populator populator = (Populator) populatorObject;
                Element element = useAction(beanToXml, populator.getKeyvalues(), populator.getClas(), parent,
                        property, getProperty());
            } else {
                Element element = useAction(beanToXml, null, "" + populatorObject, parent, property,
                        getProperty());
            }

        } else {
            BeanToXmlUtils.addAttribute(parent, getPrefix(), getName(), property.toString());
        }
    } catch (NullPointerException ex) {
        log.error("NullPointerException:" + toString());
    } catch (Exception ex) {
        throw new IllegalArgumentException(ex.getMessage() + ":" + toString(), ex);
    }
    return parent;
}

From source file:com.hookedonplay.decoviewsample.SampleFragment.java

protected DecoView getDecoView() {
    if (getView() == null) {
        return null;
    }//  w w w  . ja  v a 2 s  . c o m

    try {
        return (DecoView) getView().findViewById(R.id.dynamicArcView);
    } catch (NullPointerException npe) {
        Log.e(TAG, "Unable to resolve view " + npe.getMessage());
    }
    return null;
}

From source file:org.dspace.identifier.IdentifierServiceImpl.java

@Override
public List<String> lookup(Context context, DSpaceObject dso) {
    List<String> identifiers = new ArrayList<>();
    for (IdentifierProvider service : providers) {
        try {/*w ww.  j  a v  a 2  s  .  c om*/
            String result = service.lookup(context, dso);
            if (!StringUtils.isEmpty(result)) {
                if (log.isDebugEnabled()) {
                    try {
                        log.debug("Got an identifier from " + service.getClass().getCanonicalName() + ".");
                    } catch (NullPointerException ex) {
                        log.debug(ex.getMessage(), ex);
                    }
                }

                identifiers.add(result);
            }
        } catch (IdentifierNotFoundException ex) {
            log.info(service.getClass().getName() + " doesn't find an " + "Identifier for "
                    + contentServiceFactory.getDSpaceObjectService(dso).getTypeText(dso) + ", "
                    + dso.getID().toString() + ".");
            log.debug(ex.getMessage(), ex);
        } catch (IdentifierException ex) {
            log.error(ex.getMessage(), ex);
        }
    }

    try {
        String handle = dso.getHandle();
        if (!StringUtils.isEmpty(handle)) {
            if (!identifiers.contains(handle) && !identifiers.contains("hdl:" + handle)
                    && !identifiers.contains(handleService.getCanonicalForm(handle))) {
                // The VerionedHandleIdentifierProvider gets loaded by default
                // it returns handles without any scheme (neither hdl: nor http:).
                // If the VersionedHandleIdentifierProvider is not loaded,
                // we adds the handle in way it would.
                // Generally it would be better if identifiers would be added
                // here in a way they could be recognized.
                log.info("Adding handle '" + handle + "' to the " + "array of looked up identifiers.");
                identifiers.add(handle);
            }
        }
    } catch (Exception ex) {
        // nothing is expected here, but if an exception is thrown it
        // should not stop everything running.
        log.error(ex.getMessage(), ex);
    }

    log.debug("Found identifiers: " + identifiers.toString());
    return identifiers;
}

From source file:org.mobicents.servlet.restcomm.http.ApplicationsEndpoint.java

public Response putApplication(final String accountSid, final MultivaluedMap<String, String> data,
        final MediaType responseType) {
    Account account;/*from   w  w  w.j ava 2 s  .c om*/
    account = accountsDao.getAccount(accountSid);
    secure(account, "RestComm:Create:Applications", SecuredType.SECURED_APP);
    try {
        validate(data);
    } catch (final NullPointerException exception) {
        return status(BAD_REQUEST).entity(exception.getMessage()).build();
    }

    //        Application application = dao.getApplication(data.getFirst("FriendlyName"));
    //        if (application == null) {
    //            application = createFrom(new Sid(accountSid), data);
    //            dao.addApplication(application);
    //        } else if (!application.getAccountSid().toString().equals(account.getSid().toString())) {
    //            return status(CONFLICT)
    //                    .entity("A application with the same name was already created by another account. Please, choose a different name and try again.")
    //                    .build();
    //        }

    // application uniqueness now relies only on application SID. No checks on the FriendlyName will be done.
    Application application = createFrom(new Sid(accountSid), data);
    dao.addApplication(application);

    if (APPLICATION_XML_TYPE == responseType) {
        final RestCommResponse response = new RestCommResponse(application);
        return ok(xstream.toXML(response), APPLICATION_XML).build();
    } else if (APPLICATION_JSON_TYPE == responseType) {
        return ok(gson.toJson(application), APPLICATION_JSON).build();
    } else {
        return null;
    }
}

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

public void testBuild() throws IOException {
    try {//from w  ww.ja  va 2  s.  c o m
        RestClient.builder((HttpHost[]) null);
        fail("should have failed");
    } catch (NullPointerException e) {
        assertEquals("hosts must not be null", e.getMessage());
    }

    try {
        RestClient.builder();
        fail("should have failed");
    } catch (IllegalArgumentException e) {
        assertEquals("no hosts provided", e.getMessage());
    }

    try {
        RestClient.builder(new HttpHost("localhost", 9200), null);
        fail("should have failed");
    } catch (NullPointerException e) {
        assertEquals("host cannot be null", e.getMessage());
    }

    try (RestClient restClient = RestClient.builder(new HttpHost("localhost", 9200)).build()) {
        assertNotNull(restClient);
    }

    try {
        RestClient.builder(new HttpHost("localhost", 9200))
                .setMaxRetryTimeoutMillis(randomIntBetween(Integer.MIN_VALUE, 0));
        fail("should have failed");
    } catch (IllegalArgumentException e) {
        assertEquals("maxRetryTimeoutMillis must be greater than 0", e.getMessage());
    }

    try {
        RestClient.builder(new HttpHost("localhost", 9200)).setDefaultHeaders(null);
        fail("should have failed");
    } catch (NullPointerException e) {
        assertEquals("defaultHeaders must not be null", e.getMessage());
    }

    try {
        RestClient.builder(new HttpHost("localhost", 9200)).setDefaultHeaders(new Header[] { null });
        fail("should have failed");
    } catch (NullPointerException e) {
        assertEquals("default header must not be null", e.getMessage());
    }

    try {
        RestClient.builder(new HttpHost("localhost", 9200)).setFailureListener(null);
        fail("should have failed");
    } catch (NullPointerException e) {
        assertEquals("failureListener must not be null", e.getMessage());
    }

    try {
        RestClient.builder(new HttpHost("localhost", 9200)).setHttpClientConfigCallback(null);
        fail("should have failed");
    } catch (NullPointerException e) {
        assertEquals("httpClientConfigCallback must not be null", e.getMessage());
    }

    try {
        RestClient.builder(new HttpHost("localhost", 9200)).setRequestConfigCallback(null);
        fail("should have failed");
    } catch (NullPointerException e) {
        assertEquals("requestConfigCallback must not be null", e.getMessage());
    }

    int numNodes = randomIntBetween(1, 5);
    HttpHost[] hosts = new HttpHost[numNodes];
    for (int i = 0; i < numNodes; i++) {
        hosts[i] = new HttpHost("localhost", 9200 + i);
    }
    RestClientBuilder builder = RestClient.builder(hosts);
    if (randomBoolean()) {
        builder.setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() {
            @Override
            public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) {
                return httpClientBuilder;
            }
        });
    }
    if (randomBoolean()) {
        builder.setRequestConfigCallback(new RestClientBuilder.RequestConfigCallback() {
            @Override
            public RequestConfig.Builder customizeRequestConfig(RequestConfig.Builder requestConfigBuilder) {
                return requestConfigBuilder;
            }
        });
    }
    if (randomBoolean()) {
        int numHeaders = randomIntBetween(1, 5);
        Header[] headers = new Header[numHeaders];
        for (int i = 0; i < numHeaders; i++) {
            headers[i] = new BasicHeader("header" + i, "value");
        }
        builder.setDefaultHeaders(headers);
    }
    if (randomBoolean()) {
        builder.setMaxRetryTimeoutMillis(randomIntBetween(1, Integer.MAX_VALUE));
    }
    if (randomBoolean()) {
        String pathPrefix = (randomBoolean() ? "/" : "") + randomAsciiOfLengthBetween(2, 5);
        while (pathPrefix.length() < 20 && randomBoolean()) {
            pathPrefix += "/" + randomAsciiOfLengthBetween(3, 6);
        }
        builder.setPathPrefix(pathPrefix + (randomBoolean() ? "/" : ""));
    }
    try (RestClient restClient = builder.build()) {
        assertNotNull(restClient);
    }
}

From source file:com.krawler.esp.fileparser.wordparser.DocxParser.java

public String extractText(String filepath) {
    StringBuilder sb = new StringBuilder();

    ZipFile docxfile = null;/*from  ww  w.ja v  a2 s. c o m*/
    try {
        docxfile = new ZipFile(filepath);
    } catch (Exception e) {
        // file corrupt or otherwise could not be found
        logger.warn(e.getMessage(), e);
        return sb.toString();
    }
    InputStream in = null;
    try {
        ZipEntry ze = docxfile.getEntry("word/document.xml");
        in = docxfile.getInputStream(ze);
    } catch (NullPointerException nulle) {
        System.err.println("Expected entry word/document.xml does not exist");
        logger.warn(nulle.getMessage(), nulle);
        return sb.toString();
    } catch (IOException ioe) {
        logger.warn(ioe.getMessage(), ioe);
        return sb.toString();
    }
    Document document = null;
    try {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        document = builder.parse(in);
    } catch (ParserConfigurationException pce) {
        logger.warn(pce.getMessage(), pce);
        return sb.toString();
    } catch (SAXException sex) {
        sex.printStackTrace();
        return sb.toString();
    } catch (IOException ioe) {
        logger.warn(ioe.getMessage(), ioe);
        return sb.toString();
    } finally {
        try {
            docxfile.close();
        } catch (IOException ioe) {
            System.err.println("Exception closing file.");
            logger.warn(ioe.getMessage(), ioe);
        }
    }
    NodeList list = document.getElementsByTagName("w:t");
    List<String> content = new ArrayList<String>();
    for (int i = 0; i < list.getLength(); i++) {
        Node aNode = list.item(i);
        content.add(aNode.getFirstChild().getNodeValue());
    }
    for (String s : content) {
        sb.append(s);
    }

    return sb.toString();
}

From source file:org.mobicents.servlet.restcomm.http.ClientsEndpoint.java

public Response putClient(final String accountSid, final MultivaluedMap<String, String> data,
        final MediaType responseType) {
    secure(accountsDao.getAccount(accountSid), "RestComm:Create:Clients");
    try {/*  w  w w . j av a  2 s .c  o  m*/
        validate(data);
    } catch (final NullPointerException exception) {
        return status(BAD_REQUEST).entity(exception.getMessage()).build();
    }

    // Issue 109: https://bitbucket.org/telestax/telscale-restcomm/issue/109
    Client client = dao.getClient(data.getFirst("Login"));
    if (client == null) {
        client = createFrom(new Sid(accountSid), data);
        dao.addClient(client);
    } else if (!client.getAccountSid().toString().equals(accountSid)) {
        return status(CONFLICT).entity(
                "A client with the same name was already created by another account. Please, choose a different name and try again.")
                .build();
    }

    if (APPLICATION_XML_TYPE == responseType) {
        final RestCommResponse response = new RestCommResponse(client);
        return ok(xstream.toXML(response), APPLICATION_XML).build();
    } else if (APPLICATION_JSON_TYPE == responseType) {
        return ok(gson.toJson(client), APPLICATION_JSON).build();
    } else {
        return null;
    }
}

From source file:org.tinymediamanager.ui.movies.MovieExtendedComparator.java

@Override
public int compare(Movie movie1, Movie movie2) {
    int sortOrder = 0;

    try {//from  ww  w.j  a v a 2  s  .c  o  m
        // try to sort the chosen column
        switch (sortColumn) {
        case TITLE:
            sortOrder = stringCollator.compare(movie1.getTitleSortable().toLowerCase(Locale.ROOT),
                    movie2.getTitleSortable().toLowerCase(Locale.ROOT));
            break;

        case SORT_TITLE:
            String title1 = StringUtils.isNotBlank(movie1.getSortTitle()) ? movie1.getSortTitle()
                    : movie1.getTitleSortable();
            String title2 = StringUtils.isNotBlank(movie2.getSortTitle()) ? movie2.getSortTitle()
                    : movie2.getTitleSortable();
            sortOrder = stringCollator.compare(title1.toLowerCase(Locale.ROOT),
                    title2.toLowerCase(Locale.ROOT));
            break;

        case YEAR:
            sortOrder = stringCollator.compare(movie1.getYear(), movie2.getYear());
            break;

        case DATE_ADDED:
            sortOrder = movie1.getDateAdded().compareTo(movie2.getDateAdded());
            break;

        case WATCHED:
            Boolean watched1 = movie1.isWatched();
            Boolean watched2 = movie2.isWatched();
            sortOrder = watched1.compareTo(watched2);
            break;

        case RATING:
            sortOrder = Float.compare(movie1.getRating(), movie2.getRating());
            break;

        case RUNTIME:
            Integer runtime1 = movie1.getRuntime();
            Integer runtime2 = movie2.getRuntime();
            sortOrder = runtime1.compareTo(runtime2);
            break;

        case VIDEO_BITRATE:
            Integer videoBitrate1 = movie1.getMediaInfoVideoBitrate();
            Integer videoBitrate2 = movie2.getMediaInfoVideoBitrate();
            sortOrder = videoBitrate1.compareTo(videoBitrate2);
            break;
        }
    } catch (NullPointerException e) {
        // do nothing here. there could be
    } catch (Exception e) {
        LOGGER.warn(e.getMessage());
    }

    // sort ascending or descending
    if (sortAscending) {
        return sortOrder;
    } else {
        return sortOrder * -1;
    }
}

From source file:org.xmlactions.mapping.bean_to_xml.MapperElement.java

public Element buildXml(BeanToXml beanToXml, Element parent, Object mapClasses) {
    log.debug(toString());/*w w  w  .j  av a  2  s  .  c o m*/
    Element element = null;
    try {
        Object property = PropertyUtils.getSimpleProperty(mapClasses, getProperty());
        if (property != null) {
            log.debug("property object = " + property.getClass().getName());
            // see if we have a handler for this property
            Object populatorObject = getPopulatorQuietly(beanToXml);
            if (populatorObject != null) {
                if (populatorObject instanceof Populator) {
                    Populator populator = (Populator) populatorObject;
                    element = useAction(beanToXml, populator.getKeyvalues(), populator.getClas(), parent,
                            property, getProperty());
                } else {
                    element = useAction(beanToXml, null, "" + populatorObject, parent, property, getProperty());
                }
            } else {
                if (property instanceof List) {
                    element = useAction(beanToXml, null, defaultListPopulator, parent, property, getProperty());
                } else if (property instanceof Object[]) {
                    element = useAction(beanToXml, null, defaultArrayPopulator, parent, property,
                            getProperty());
                } else {
                    Bean bean = beanToXml.findBeanByName(this.getBean_ref());
                    element = bean.processBean(beanToXml, parent, property, getPrefix(), getName());
                }
            }
        }
    } catch (NullPointerException ex) {
        log.error("NullPointerException:" + toString());
    } catch (Exception ex) {
        throw new IllegalArgumentException(ex.getMessage() + ":" + toString(), ex);
    }
    return element;
}