Example usage for java.lang.reflect UndeclaredThrowableException UndeclaredThrowableException

List of usage examples for java.lang.reflect UndeclaredThrowableException UndeclaredThrowableException

Introduction

In this page you can find the example usage for java.lang.reflect UndeclaredThrowableException UndeclaredThrowableException.

Prototype

public UndeclaredThrowableException(Throwable undeclaredThrowable) 

Source Link

Document

Constructs an UndeclaredThrowableException with the specified Throwable .

Usage

From source file:org.apache.tez.runtime.library.common.shuffle.orderedgrouped.Shuffle.java

private void handleThrowable(Throwable t) throws IOException, InterruptedException {
    if (t instanceof IOException) {
        throw (IOException) t;
    } else if (t instanceof InterruptedException) {
        throw (InterruptedException) t;
    } else {//from  w ww. j a  v a2 s  .c o  m
        throw new UndeclaredThrowableException(t);
    }
}

From source file:br.com.lucasisrael.regra.reflections.TratamentoReflections.java

/**
 * Rethrow the given {@link Throwable exception}, which is presumably the
 * <em>target exception</em> of an {@link InvocationTargetException}. Should
 * only be called if no checked exception is expected to be thrown by the
 * target method./*from  w  w w  . j av a 2 s . c  om*/
 * <p>Rethrows the underlying exception cast to an {@link RuntimeException} or
 * {@link Error} if appropriate; otherwise, throws an
 * {@link IllegalStateException}.
 * @param ex the exception to rethrow
 * @throws RuntimeException the rethrown exception
 */
public static void rethrowRuntimeException(Throwable ex) {
    if (ex instanceof RuntimeException) {
        throw (RuntimeException) ex;
    }
    if (ex instanceof Error) {
        throw (Error) ex;
    }
    throw new UndeclaredThrowableException(ex);
}

From source file:org.opennms.ng.services.databaseschemaconfig.JdbcFilterDao.java

private List<InetAddress> getIPAddressList(final String rule, final boolean filterDeleted)
        throws FilterParseException {
    final List<InetAddress> resultList = new ArrayList<InetAddress>();
    String sqlString;/*from  w  w w . j a v  a2 s . c  o  m*/

    LOG.debug("Filter.getIPAddressList({})", rule);

    // get the database connection
    Connection conn = null;
    final DBUtils d = new DBUtils(getClass());
    try {
        // parse the rule and get the sql select statement
        sqlString = getSQLStatement(rule);

        if (filterDeleted) {
            if (!sqlString.contains("isManaged")) {
                sqlString += " AND (ipInterface.isManaged != 'D' or ipInterface.isManaged IS NULL)";
            }
        }

        conn = getDataSource().getConnection();
        d.watch(conn);

        LOG.debug("Filter.getIPAddressList({}): SQL statement: {}", rule, sqlString);

        // execute query and return the list of ip addresses
        final Statement stmt = conn.createStatement();
        d.watch(stmt);
        final ResultSet rset = stmt.executeQuery(sqlString);
        d.watch(rset);

        // fill up the array list if the result set has values
        if (rset != null) {
            // Iterate through the result and build the array list
            while (rset.next()) {
                resultList.add(addr(rset.getString(1)));
            }
        }

    } catch (final FilterParseException e) {
        LOG.warn("Filter Parse Exception occurred getting IP List.", e);
        throw new FilterParseException(
                "Filter Parse Exception occurred getting IP List: " + e.getLocalizedMessage(), e);
    } catch (final SQLException e) {
        LOG.warn("SQL Exception occurred getting IP List.", e);
        throw new FilterParseException("SQL Exception occurred getting IP List: " + e.getLocalizedMessage(), e);
    } catch (final Throwable e) {
        LOG.error("Exception getting database connection.", e);
        throw new UndeclaredThrowableException(e);
    } finally {
        d.cleanUp();
    }

    LOG.debug("Filter.getIPAddressList({}): resultList = {}", rule, resultList);
    return resultList;
}

From source file:org.alfresco.traitextender.AJExtender.java

static Throwable asCheckThrowable(Throwable error, Class<?>... checkedThrowableTypes) {
    Class<? extends Throwable> errorClass = error.getClass();
    for (int i = 0; i < checkedThrowableTypes.length; i++) {
        if (errorClass.equals(checkedThrowableTypes[i])) {
            return error;
        }/*  ww  w  .  ja  va2  s  .c  om*/
    }
    return new UndeclaredThrowableException(error);
}

From source file:br.com.lucasisrael.regra.reflections.TratamentoReflections.java

/**
 * Rethrow the given {@link Throwable exception}, which is presumably the
 * <em>target exception</em> of an {@link InvocationTargetException}. Should
 * only be called if no checked exception is expected to be thrown by the
 * target method.//from ww w.j ava  2s  .  c o  m
 * <p>Rethrows the underlying exception cast to an {@link Exception} or
 * {@link Error} if appropriate; otherwise, throws an
 * {@link IllegalStateException}.
 * @param ex the exception to rethrow
 * @throws Exception the rethrown exception (in case of a checked exception)
 */
public static void rethrowException(Throwable ex) throws Exception {
    if (ex instanceof Exception) {
        throw (Exception) ex;
    }
    if (ex instanceof Error) {
        throw (Error) ex;
    }
    throw new UndeclaredThrowableException(ex);
}

From source file:org.alfresco.traitextender.AJExtender.java

/**
 * Extension-bypass closure runner method. <br>
 * Sets up adequate call contexts to avoid exception calling and than
 * delegates to the given closure.//  ww w .  ja  v a  2 s . co  m
 * 
 * @param closure
 * @return
 */
public static <R> R run(AJExtender.ExtensionBypass<R> closure) {
    try {
        return throwableRun(closure);
    } catch (Error | RuntimeException error) {
        throw error;
    } catch (Throwable error) {
        throw new UndeclaredThrowableException(error);
    }
}

From source file:Base64.java

/** Converts the given byte array into a base64 encoded character
 * array./*  w  w w. j  a  v a2  s .c  o m*/
 * @param pBuffer The buffer being encoded.
 * @param pOffset Offset in buffer, where to begin encoding.
 * @param pLength Number of bytes being encoded.
 * @param pLineSize Size of one line in characters, must be a multiple
 * of four. Zero indicates, that no line wrapping should occur.
 * @param pSeparator Line separator or null, in which case the default value
 * {@link #LINE_SEPARATOR} is used.
 * @return Character array of encoded bytes.
 */
public static String encode(byte[] pBuffer, int pOffset, int pLength, int pLineSize, String pSeparator) {
    StringWriter sw = new StringWriter();
    OutputStream ostream = newEncoder(sw, pLineSize, pSeparator);
    try {
        ostream.write(pBuffer, pOffset, pLength);
        ostream.close();
    } catch (IOException e) {
        throw new UndeclaredThrowableException(e);
    }
    return sw.toString();
}

From source file:com.google.dexmaker.ProxyBuilder.java

private static RuntimeException launderCause(InvocationTargetException e) {
    Throwable cause = e.getCause();
    // Errors should be thrown as they are.
    if (cause instanceof Error) {
        throw (Error) cause;
    }/* w ww . j a  va  2  s.c o  m*/
    // RuntimeException can be thrown as-is.
    if (cause instanceof RuntimeException) {
        throw (RuntimeException) cause;
    }
    // Declared exceptions will have to be wrapped.
    throw new UndeclaredThrowableException(cause);
}

From source file:org.opennms.ng.services.databaseschemaconfig.JdbcFilterDao.java

/** {@inheritDoc} */
@Override/*from w w  w. ja va 2  s  .c  o  m*/
public boolean isRuleMatching(final String rule) throws FilterParseException {
    boolean matches = false;
    String sqlString;

    LOG.debug("Filter.isRuleMatching({})", rule);

    final DBUtils d = new DBUtils(getClass());

    // get the database connection
    Connection conn = null;
    try {
        conn = getDataSource().getConnection();
        d.watch(conn);

        // parse the rule and get the sql select statement
        sqlString = getSQLStatement(rule) + " LIMIT 1";
        LOG.debug("Filter.isRuleMatching({}): SQL statement: {}", rule, sqlString);

        // execute query and return the list of ip addresses
        final Statement stmt = conn.createStatement();
        d.watch(stmt);
        final ResultSet rset = stmt.executeQuery(sqlString);
        d.watch(rset);

        // we only want to check if zero or one rows were fetched, so just
        // return the output from rset.next()
        matches = rset.next();
        LOG.debug("isRuleMatching: rule \"{}\" {} an entry in the database", rule,
                matches ? "matches" : "does not match");
    } catch (final FilterParseException e) {
        LOG.warn("Filter Parse Exception occurred testing rule \"{}\" for matching results.", rule, e);
        throw new FilterParseException("Filter Parse Exception occurred testing rule \"" + rule
                + "\" for matching results: " + e.getLocalizedMessage(), e);
    } catch (final SQLException e) {
        LOG.warn("SQL Exception occurred testing rule \"{}\" for matching results.", e);
        throw new FilterParseException("SQL Exception occurred testing rule \"" + rule
                + "\" for matching results: " + e.getLocalizedMessage(), e);
    } catch (final Throwable e) {
        LOG.error("Exception getting database connection.", e);
        throw new UndeclaredThrowableException(e);
    } finally {
        d.cleanUp();
    }

    return matches;
}

From source file:org.opennms.ng.services.scheduler.LegacyScheduler.java

/**
 * The main method of the scheduler. This method is responsible for checking
 * the runnable queues for ready objects and then enqueuing them into the
 * thread pool for execution.// ww  w. j av a2 s  .  c  o m
 */
@Override
public void run() {
    synchronized (this) {
        m_status = RUNNING;
    }

    LOG.debug("run: scheduler running");

    /*
     * Loop until a fatal exception occurs or until
     * the thread is interrupted.
     */
    for (;;) {
        /*
         * Block if there is nothing in the queue(s).
         * When something is added to the queue it
         * signals us to wakeup.
         */
        synchronized (this) {

            if (m_status != RUNNING && m_status != PAUSED && m_status != PAUSE_PENDING
                    && m_status != RESUME_PENDING) {
                LOG.debug("run: status = " + m_status + ", time to exit");
                break;
            }

            // if paused or pause pending then block
            while (m_status == PAUSE_PENDING || m_status == PAUSED) {
                if (m_status == PAUSE_PENDING) {
                    LOG.debug("run: pausing.");
                }
                m_status = PAUSED;
                try {
                    wait();
                } catch (InterruptedException ex) {
                    // exit
                    break;
                }
            }

            // if resume pending then change to running

            if (m_status == RESUME_PENDING) {
                LOG.debug("run: resuming.");

                m_status = RUNNING;
            }

            if (m_scheduled == 0) {
                try {
                    LOG.debug("run: no ready runnables scheduled, waiting...");
                    wait();
                } catch (InterruptedException ex) {
                    break;
                }
            }
        }

        /*
         * Cycle through the queues checking for
         * what's ready to run.  The queues are keyed
         * by the interval, but the mapped elements
         * are peekable fifo queues.
         */
        int runned = 0;
        synchronized (m_queues) {
            /*
             * Get an iterator so that we can cycle
             * through the queue elements.
             */
            for (Entry<Long, PeekableFifoQueue<ReadyRunnable>> entry : m_queues.entrySet()) {
                /*
                 * Peak for Runnable objects until
                 * there are no more ready runnables.
                 *
                 * Also, only go through each queue once!
                 * if we didn't add a count then it would
                 * be possible to starve other queues.
                 */
                PeekableFifoQueue<ReadyRunnable> in = entry.getValue();
                ReadyRunnable readyRun = null;
                int maxLoops = in.size();
                do {
                    try {
                        readyRun = in.peek();
                        if (readyRun != null && readyRun.isReady()) {
                            LOG.debug("run: found ready runnable {}", readyRun);

                            /*
                             * Pop the interface/readyRunnable from the
                             * queue for execution.
                             */
                            in.remove();

                            // Add runnable to the execution queue
                            m_runner.execute(readyRun);
                            ++runned;
                        }
                    } catch (InterruptedException e) {
                        return; // jump all the way out
                    } catch (RejectedExecutionException e) {
                        throw new UndeclaredThrowableException(e);
                    }

                } while (readyRun != null && readyRun.isReady() && --maxLoops > 0);
            }
        }

        /*
         * Wait for 1 second if there were no runnables
         * executed during this loop, otherwise just
         * start over.
         */
        synchronized (this) {
            m_scheduled -= runned;
            if (runned == 0) {
                try {
                    wait(1000);
                } catch (InterruptedException ex) {
                    break; // exit for loop
                }
            }
        }

    }

    LOG.debug("run: scheduler exiting, state = STOPPED");
    synchronized (this) {
        m_status = STOPPED;
    }

}