Example usage for java.lang RuntimeException getCause

List of usage examples for java.lang RuntimeException getCause

Introduction

In this page you can find the example usage for java.lang RuntimeException 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:com.espertech.esper.epl.parse.ParseHelper.java

/**
 * Parse expression using the rule the ParseRuleSelector instance supplies.
 *
 * @param expression           - text to parse
 * @param parseRuleSelector    - parse rule to select
 * @param addPleaseCheck       - true to include depth paraphrase
 * @param eplStatementErrorMsg - text for error
 * @return AST - syntax tree//from   w  ww.  j a  va  2s  .c  om
 * @throws EPException when the AST could not be parsed
 */
public static ParseResult parse(String expression, String eplStatementErrorMsg, boolean addPleaseCheck,
        ParseRuleSelector parseRuleSelector, boolean rewriteScript) throws EPException {
    if (log.isDebugEnabled()) {
        log.debug(".parse Parsing expr=" + expression);
    }

    CharStream input;
    try {
        input = new NoCaseSensitiveStream(new StringReader(expression));
    } catch (IOException ex) {
        throw new EPException("IOException parsing expression '" + expression + '\'', ex);
    }

    EsperEPL2GrammarLexer lex = new EsperEPL2GrammarLexer(input);
    TokenRewriteStream tokens = new TokenRewriteStream(lex);
    EsperEPL2GrammarParser parser = new EsperEPL2GrammarParser(tokens);

    Tree tree;
    try {
        tree = parseRuleSelector.invokeParseRule(parser);
    } catch (RuntimeException e) {
        if (log.isDebugEnabled()) {
            log.debug("Error parsing statement [" + eplStatementErrorMsg + "]", e);
        }
        if (e.getCause() instanceof RecognitionException) {
            throw ExceptionConvertor.convertStatement((RecognitionException) e.getCause(), eplStatementErrorMsg,
                    addPleaseCheck, parser);
        } else {
            throw e;
        }
    } catch (RecognitionException ex) {
        if (rewriteScript && isContainsScriptExpression(tokens)) {
            ScriptResult rewriteExpression = rewriteTokensScript(tokens);
            ParseResult result = parse(rewriteExpression.getRewrittenEPL(), eplStatementErrorMsg,
                    addPleaseCheck, parseRuleSelector, false);
            return new ParseResult(result.getTree(), result.getExpressionWithoutAnnotations(),
                    result.getTokenStream(), rewriteExpression.getScripts());
        }

        log.debug("Error parsing statement [" + expression + "]", ex);
        throw ExceptionConvertor.convertStatement(ex, eplStatementErrorMsg, addPleaseCheck, parser);
    }

    // if we are re-writing scripts and contain a script, then rewrite
    if (rewriteScript && isContainsScriptExpression(tokens)) {
        ScriptResult rewriteExpression = rewriteTokensScript(tokens);
        ParseResult result = parse(rewriteExpression.getRewrittenEPL(), rewriteExpression.getRewrittenEPL(),
                addPleaseCheck, parseRuleSelector, false);
        return new ParseResult(result.getTree(), result.getExpressionWithoutAnnotations(),
                result.getTokenStream(), rewriteExpression.getScripts());
    }

    if (log.isDebugEnabled()) {
        log.debug(".parse Dumping AST...");
        ASTUtil.dumpAST(tree);
    }

    return new ParseResult(tree, getNoAnnotation(expression, tree, tokens), tokens,
            Collections.<String>emptyList());
}

From source file:de.micromata.genome.jpa.EmgrFactory.java

/**
 * Convert exception.//w  ww. j  a v  a 2  s .  c  o  m
 *
 * @param ex the ex
 * @return the runtime exception
 */
public static RuntimeException convertException(RuntimeException ex) {
    if (ex instanceof QueryTimeoutException) {
        // this is a oracle/hibernate bug workouround.
        // hibernate think this is is a query timeout, but should a DataException
        if (ex.getCause() instanceof org.hibernate.QueryTimeoutException) {
            org.hibernate.QueryTimeoutException qto = (org.hibernate.QueryTimeoutException) ex.getCause();
            if (qto.getCause() instanceof SQLException) {
                SQLException sqlex = (SQLException) qto.getCause();
                // ORA-12899
                if (sqlex.getErrorCode() == 12899) {
                    return new DataPersistenceException(ex.getMessage(), qto.getSQL(), sqlex.getSQLState(), ex);
                }
            }
        }
    }
    if (ex instanceof PersistenceException) {
        Throwable cause = ex.getCause();
        if (cause instanceof ConstraintViolationException) {
            ConstraintViolationException cve = (ConstraintViolationException) cause;
            cve.getMessage();
            String sql = cve.getSQL();
            return new ConstraintPersistenceException(cve.getMessage(), sql, cve.getSQLState(),
                    cve.getConstraintName(), ex);
        } else if (cause instanceof DataException) {
            DataException dex = (DataException) cause;
            return new DataPersistenceException(ex.getMessage(), dex.getSQL(), dex.getSQLState(), ex);
        } else if (cause instanceof PropertyValueException) {
            if (StringUtils.startsWith(cause.getMessage(), "not-null ") == true) {
                return new NullableConstraintPersistenceException(ex.getMessage(), ex);
            }
        }
    }
    return ex;
}

From source file:com.fujitsu.dc.core.model.impl.es.CellEsImpl.java

/**
 * ID ??Cell??Cell?Cell??./*w  ww  .  j  av a2s .c o m*/
 * @param queryKey Cell??(Cell??)
 * @param queryValue Cell????
 * @param uriInfo UriInfo
 * @return Cell  ?Cell??????????queryKey?????null
 */
public static Cell findCell(String queryKey, String queryValue, UriInfo uriInfo) {
    if (!queryKey.equals("_id") && !queryKey.equals("s.Name.untouched")) {
        return null;
    }
    // URl???Cell?????????Cell??????null??
    if (!validatePropertyRegEx(queryValue, Common.PATTERN_NAME)) {
        return null;
    }

    EntitySetAccessor ecCells = EsModel.cell();
    CellEsImpl ret = new CellEsImpl();

    Map<String, Object> cache = CellCache.get(queryValue);
    if (cache == null) {
        Map<String, Object> source = new HashMap<String, Object>();
        Map<String, Object> filter = new HashMap<String, Object>();
        Map<String, Object> term = new HashMap<String, Object>();

        term.put(queryKey, queryValue);
        filter.put("term", term);
        source.put("query", QueryMapFactory.filteredQuery(null, filter));

        DcSearchResponse resp = ecCells.search(source);
        if ((resp == null) || (resp.getHits().getCount() == 0)) {
            return null;
        }
        DcSearchHit hit = resp.getHits().getAt(0);
        ret.setJson(hit.getSource());
        ret.id = hit.getId();

        cache = hit.getSource();
        cache.put("_id", hit.getId());
        try {
            CellCache.cache(queryValue, cache);
        } catch (RuntimeException e) {
            if (e.getCause() instanceof CheckedOperationTimeoutException) {
                // memcached????????????
                log.info("Faild to cache Cell info.");
            } else {
                // ??????????
                throw DcCoreException.Server.SERVER_CONNECTION_ERROR;
            }
        }
    } else {
        ret.setJson(cache);
        ret.id = (String) cache.get("_id");
    }

    // URL???Set
    StringBuilder urlSb = new StringBuilder();
    UriBuilder uriBuilder = uriInfo.getBaseUriBuilder();
    uriBuilder.scheme(DcCoreConfig.getUnitScheme());
    urlSb.append(uriBuilder.build().toASCIIString());
    urlSb.append(ret.getName());
    urlSb.append("/");
    ret.url = urlSb.toString();
    return ret;
}

From source file:io.personium.core.model.impl.es.CellEsImpl.java

/**
 * ID ??Cell??Cell?Cell??./*from   w w  w.  java 2 s . com*/
 * @param queryKey
 *            Cell??(Cell??)
 * @param queryValue
 *            Cell????
 * @param uriInfo
 *            UriInfo
 * @return Cell  ?Cell??????????queryKey?????null
 */
public static Cell findCell(String queryKey, String queryValue, UriInfo uriInfo) {
    if (!queryKey.equals("_id") && !queryKey.equals("s.Name.untouched")) {
        return null;
    }
    // URl???Cell?????????Cell??????null??
    if (!validatePropertyRegEx(queryValue, Common.PATTERN_NAME)) {
        return null;
    }

    EntitySetAccessor ecCells = EsModel.cell();
    CellEsImpl ret = new CellEsImpl();

    Map<String, Object> cache = CellCache.get(queryValue);
    if (cache == null) {
        Map<String, Object> source = new HashMap<String, Object>();
        Map<String, Object> filter = new HashMap<String, Object>();
        Map<String, Object> term = new HashMap<String, Object>();

        term.put(queryKey, queryValue);
        filter.put("term", term);
        source.put("query", QueryMapFactory.filteredQuery(null, filter));

        PersoniumSearchResponse resp = ecCells.search(source);
        if (resp == null || resp.getHits().getCount() == 0) {
            return null;
        }
        PersoniumSearchHit hit = resp.getHits().getAt(0);
        ret.setJson(hit.getSource());
        ret.id = hit.getId();

        cache = hit.getSource();
        cache.put("_id", hit.getId());
        try {
            CellCache.cache(queryValue, cache);
        } catch (RuntimeException e) {
            if (e.getCause() instanceof CheckedOperationTimeoutException) {
                // memcached????????????
                log.info("Faild to cache Cell info.");
            } else {
                // ??????????
                throw PersoniumCoreException.Server.SERVER_CONNECTION_ERROR;
            }
        }
    } else {
        ret.setJson(cache);
        ret.id = (String) cache.get("_id");
    }
    ret.url = getBaseUri(uriInfo, ret.name);
    return ret;
}

From source file:ubic.gemma.core.loader.expression.arrayExpress.SDRFFetcherTest.java

public final void testFetch() {
    try {/*  ww w.ja v a2s  .c  o  m*/
        SDRFFetcher f = new SDRFFetcher();
        Collection<LocalFile> fetch = f.fetch("E-SMDB-1853");
        TestCase.assertEquals(1, fetch.size());
    } catch (RuntimeException e) {
        if (e.getCause() instanceof java.net.ConnectException) {
            SDRFFetcherTest.log.warn("Test skipped due to connection exception");
        } else if (e.getCause() instanceof java.net.UnknownHostException) {
            SDRFFetcherTest.log.warn("Test skipped due to unknown host exception");
        } else {
            throw (e);
        }
    }
}

From source file:com.excilys.ebi.utils.spring.log.slf4j.InjectLoggerTest.java

/**
 * Check that an IllegalStateException is thrown if the logger member is
 * static// w  ww  .j av  a 2  s  .  co m
 */
@Test(expected = IllegalArgumentException.class)
public void testStaticLoggerInjectionFailure() throws Throwable {

    try {
        new ClassPathXmlApplicationContext(
                "com/excilys/ebi/utils/spring/log/slf4j/bean-with-static-logger-context.xml");

    } catch (RuntimeException e) {
        throw e.getCause();
    }
}

From source file:org.eclipse.hawkbit.artifact.repository.ArtifactFilesystemTest.java

@Test
@Description("Verifies that an exception is thrown on opening an InputStream when file does not exists")
public void getInputStreamOfNonExistingFileThrowsException() {
    final File file = new File("fileWhichTotalDoesNotExists");
    final ArtifactFilesystem underTest = new ArtifactFilesystem(file, "fileWhichTotalDoesNotExists",
            new DbArtifactHash("1", "2"), 0L, null);
    try {//from www. j  a  v a 2 s  . com
        underTest.getFileInputStream();
        Assertions.fail("Expected a FileNotFoundException because file does not exists");
    } catch (final RuntimeException e) {
        assertThat(e.getCause()).isInstanceOf(FileNotFoundException.class);
    }
}

From source file:com.thoughtworks.go.domain.ArtifactMd5ChecksumsTest.java

@Test
public void shouldThrowAnExceptionIfTheLoadingFails() throws IOException {
    try {//from   w ww . j a va  2s  . co  m
        file.delete();
        new ArtifactMd5Checksums(file);
        fail("Should have failed because of an invalid properites file");
    } catch (RuntimeException e) {
        assertThat(e.getCause(), instanceOf(IOException.class));
        assertThat(e.getMessage(), is(String
                .format("[Checksum Verification] Could not load the MD5 from the checksum file '%s'", file)));
    }
}

From source file:com.rackspacecloud.blueflood.io.serializers.astyanax.StringSerializerTest.java

@Test(expected = SerializationException.class)
public void testSerializerForStringShouldFail() throws Throwable {
    try {//from ww w . ja  v a 2s. c o m
        Serializers.serializerFor(String.class);
    } catch (RuntimeException re) {
        throw re.getCause();
    }
}

From source file:com.rackspacecloud.blueflood.io.serializers.astyanax.StringSerializerTest.java

@Test(expected = UnexpectedStringSerializationException.class)
public void testStringFullSerializationShouldFail() throws Throwable {
    ByteArrayOutputStream baos = serializeString(TEST_STRING);
    ByteBuffer byteBuffer = ByteBuffer.wrap(baos.toByteArray());
    try {//from  w  ww .j a va2s .c o  m
        Serializers.serializerFor(Object.class).fromByteBuffer(byteBuffer);
    } catch (RuntimeException re) {
        throw re.getCause();
    }
}