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.event.property.PropertyParser.java

/**
 * Parses a given property name returning an AST.
 * @param propertyName to parse/* w  ww  .  j  ava 2 s  .  c  o m*/
 * @return AST syntax tree
 */
public static Tree parse(String propertyName) {
    CharStream input;
    try {
        input = new NoCaseSensitiveStream(new StringReader(propertyName));
    } catch (IOException ex) {
        throw new PropertyAccessException("IOException parsing property name '" + propertyName + '\'', ex);
    }

    EsperEPL2GrammarLexer lex = new EsperEPL2GrammarLexer(input);
    CommonTokenStream tokens = new CommonTokenStream(lex);
    EsperEPL2GrammarParser g = new EsperEPL2GrammarParser(tokens);
    EsperEPL2GrammarParser.startEventPropertyRule_return r;

    try {
        r = g.startEventPropertyRule();
    } catch (RuntimeException e) {
        if (log.isDebugEnabled()) {
            log.debug("Error parsing property expression [" + propertyName + "]", e);
        }
        if (e.getCause() instanceof RecognitionException) {
            throw ExceptionConvertor.convertProperty((RecognitionException) e.getCause(), propertyName, true,
                    g);
        } else {
            throw e;
        }
    } catch (RecognitionException e) {
        // Check for keywords and escape each, parse again
        String escapedPropertyName = escapeKeywords(tokens);

        CharStream inputEscaped;
        try {
            inputEscaped = new NoCaseSensitiveStream(new StringReader(escapedPropertyName));
        } catch (IOException ex) {
            throw new PropertyAccessException("IOException parsing property name '" + propertyName + '\'', ex);
        }

        EsperEPL2GrammarLexer lexEscaped = new EsperEPL2GrammarLexer(inputEscaped);
        CommonTokenStream tokensEscaped = new CommonTokenStream(lexEscaped);
        EsperEPL2GrammarParser gEscaped = new EsperEPL2GrammarParser(tokensEscaped);
        EsperEPL2GrammarParser.startEventPropertyRule_return rEscaped;

        try {
            rEscaped = gEscaped.startEventPropertyRule();
            return (Tree) rEscaped.getTree();
        } catch (Exception eEscaped) {
        }

        throw ExceptionConvertor.convertProperty(e, propertyName, true, g);
    }

    return (Tree) r.getTree();
}

From source file:com.aliyun.odps.local.common.utils.LocalRunUtils.java

@SuppressWarnings({ "unchecked", "rawtypes" })
public static Collection<File> listFiles(final File dir, final String relativePath) throws IOException {
    // privileged code, for this method may be invoked by user code
    try {//from w  w w  .  jav  a  2 s  .  co m
        return (Collection<File>) AccessController.doPrivileged(new PrivilegedAction() {
            public Object run() {
                File relativeDir = new File(dir, relativePath);
                checkParent(dir, relativePath);
                if (relativeDir.isDirectory()) {
                    return FileUtils.listFiles(relativeDir, new InternalIOFilter(), new InternalIOFilter());
                } else {
                    Collection<File> files = new java.util.LinkedList<File>();
                    files.add(relativeDir);
                    return files;
                }
            }
        });
    } catch (RuntimeException e) {
        if (e.getCause() instanceof IOException) {
            throw (IOException) e.getCause();
        } else {
            throw e;
        }
    }
}

From source file:de.tuberlin.uebb.jbop.access.ClassAccessor.java

private static <T> T executePrivileged(final PrivilegedAction<T> action) throws JBOPClassException {
    try {//from  ww  w.j a  v a 2  s  .  c  om
        return AccessController.doPrivileged(action);
    } catch (final RuntimeException re) {
        throw new JBOPClassException(re.getMessage(), re.getCause());
    }
}

From source file:com.espertech.esper.epl.parse.ParseHelper.java

/**
 * Walk parse tree starting at the rule the walkRuleSelector supplies.
 *
 * @param ast                     - ast to walk
 * @param walker                  - walker instance
 * @param walkRuleSelector        - walk rule
 * @param expression              - the expression we are walking in string form
 * @param eplStatementForErrorMsg - statement text for error messages
 *//*ww w  .  j av a 2s . c  o m*/
public static void walk(Tree ast, EPLTreeWalker walker, WalkRuleSelector walkRuleSelector, String expression,
        String eplStatementForErrorMsg) {
    // Walk tree
    try {
        if (log.isDebugEnabled()) {
            log.debug(".walk Walking AST using walker " + walker.getClass().getName());
        }

        walkRuleSelector.invokeWalkRule(walker);

        if (log.isDebugEnabled()) {
            log.debug(".walk AST tree after walking");
            ASTUtil.dumpAST(ast);
        }
    } catch (RuntimeException e) {
        log.info("Error walking statement [" + expression + "]", e);
        if (e.getCause() instanceof RecognitionException) {
            throw ExceptionConvertor.convert((RecognitionException) e.getCause(), eplStatementForErrorMsg,
                    walker);
        } else {
            throw e;
        }
    } catch (RecognitionException e) {
        log.info("Error walking statement [" + expression + "]", e);
        throw ExceptionConvertor.convert(e, eplStatementForErrorMsg, walker);
    }
}

From source file:org.apache.hadoop.ipc.CallQueueManager.java

private static <T extends RpcScheduler> T createScheduler(Class<T> theClass, int priorityLevels, String ns,
        Configuration conf) {/*from   w  ww. j a  v  a2 s.com*/
    // Used for custom, configurable scheduler
    try {
        Constructor<T> ctor = theClass.getDeclaredConstructor(int.class, String.class, Configuration.class);
        return ctor.newInstance(priorityLevels, ns, conf);
    } catch (RuntimeException e) {
        throw e;
    } catch (InvocationTargetException e) {
        throw new RuntimeException(theClass.getName() + " could not be constructed.", e.getCause());
    } catch (Exception e) {
    }

    try {
        Constructor<T> ctor = theClass.getDeclaredConstructor(int.class);
        return ctor.newInstance(priorityLevels);
    } catch (RuntimeException e) {
        throw e;
    } catch (InvocationTargetException e) {
        throw new RuntimeException(theClass.getName() + " could not be constructed.", e.getCause());
    } catch (Exception e) {
    }

    // Last attempt
    try {
        Constructor<T> ctor = theClass.getDeclaredConstructor();
        return ctor.newInstance();
    } catch (RuntimeException e) {
        throw e;
    } catch (InvocationTargetException e) {
        throw new RuntimeException(theClass.getName() + " could not be constructed.", e.getCause());
    } catch (Exception e) {
    }

    // Nothing worked
    throw new RuntimeException(theClass.getName() + " could not be constructed.");
}

From source file:org.lgna.common.ComponentThread.java

public static Throwable unwrapRuntimeException(Throwable t) {
    if (t instanceof RuntimeException) {
        RuntimeException re = (RuntimeException) t;
        t = re.getCause();
        if (t == null) {
            return re;
        } else {/*from w  w w. j a  v  a 2 s .  com*/
            return unwrapRuntimeException(t);
        }
    } else {
        return t;
    }
}

From source file:org.eclipse.cft.server.core.internal.CloudErrorUtil.java

/**
 * If the error is a server communication error, it wraps it in a
 * {@link CoreException} with user-friendly message. If the server
 * communciation error is due to {@link SSLPeerUnverifiedException}, the
 * latter is set as the cause for the wrapped CoreException. Otherwise,
 * returns the error as the cause in a CoreException. Always returns a
 * {@link CoreException}.//  w  w  w  . j av  a  2 s .  c  o m
 * @param e
 * @return CoreException wrapper if communication error with server, or
 * otherwise return CoreException with original error as cause. Never null.
 * 
 */
public static CoreException checkServerCommunicationError(RuntimeException e) {
    if (e != null && e.getCause() instanceof IOException) {
        // Set the cause for SSL
        if ((e.getCause() instanceof SSLPeerUnverifiedException)) {
            return toCoreException(e.getCause());
        } else {
            // Log other IO errors.
            String errorMessage = NLS.bind(Messages.ERROR_UNABLE_TO_COMMUNICATE_SERVER, e.getMessage());
            CloudFoundryPlugin.logError(errorMessage, e);
            return new CoreException(new Status(IStatus.ERROR, CloudFoundryPlugin.PLUGIN_ID, errorMessage));
        }
    } else {
        return checkRestException(e);
    }
}

From source file:org.neo4j.backup.TestBackup.java

private static void assertStoreIsLocked(String path) {
    try {/* w w  w  .j  av  a2 s .c  om*/
        new TestGraphDatabaseFactory().newEmbeddedDatabase(path).shutdown();
        fail("Could start up database in same process, store not locked");
    } catch (RuntimeException ex) {
        assertThat(ex.getCause().getCause(), instanceOf(StoreLockException.class));
    }

    StartupChecker proc = new LockProcess().start(path);
    try {
        assertFalse("Could start up database in subprocess, store is not locked", proc.startupOk());
    } finally {
        SubProcess.stop(proc);
    }
}

From source file:org.apache.hadoop.hdfs.NameNodeProxies.java

/** Gets the configured Failover proxy provider's class */
@VisibleForTesting//w  w  w.  ja  v  a  2 s .c  o  m
public static <T> Class<FailoverProxyProvider<T>> getFailoverProxyProviderClass(Configuration conf,
        URI nameNodeUri, Class<T> xface) throws IOException {
    if (nameNodeUri == null) {
        return null;
    }
    String host = nameNodeUri.getHost();

    String configKey = DFS_CLIENT_FAILOVER_PROXY_PROVIDER_KEY_PREFIX + "." + host;
    try {
        @SuppressWarnings("unchecked")
        Class<FailoverProxyProvider<T>> ret = (Class<FailoverProxyProvider<T>>) conf.getClass(configKey, null,
                FailoverProxyProvider.class);
        if (ret != null) {
            // If we found a proxy provider, then this URI should be a logical NN.
            // Given that, it shouldn't have a non-default port number.
            int port = nameNodeUri.getPort();
            if (port > 0 && port != NameNode.DEFAULT_PORT) {
                throw new IOException("Port " + port + " specified in URI " + nameNodeUri + " but host '" + host
                        + "' is a logical (HA) namenode" + " and does not use port information.");
            }
        }
        return ret;
    } catch (RuntimeException e) {
        if (e.getCause() instanceof ClassNotFoundException) {
            throw new IOException("Could not load failover proxy provider class " + conf.get(configKey)
                    + " which is configured for authority " + nameNodeUri, e);
        } else {
            throw e;
        }
    }
}

From source file:org.apache.phoenix.util.ServerUtil.java

private static Table getTableFromSingletonPool(RegionCoprocessorEnvironment env, TableName tableName)
        throws IOException {
    // It's ok to not ever do a pool.close() as we're storing a single
    // table only. The HTablePool holds no other resources that this table
    // which will be closed itself when it's no longer needed.
    Connection conn = ConnectionFactory.getConnection(ConnectionType.DEFAULT_SERVER_CONNECTION, env);
    try {/*from ww  w  .  j a v  a2  s  . c o  m*/
        return conn.getTable(tableName);
    } catch (RuntimeException t) {
        // handle cases that an IOE is wrapped inside a RuntimeException like HTableInterface#createHTableInterface
        if (t.getCause() instanceof IOException) {
            throw (IOException) t.getCause();
        } else {
            throw t;
        }
    }
}