Example usage for java.lang RuntimeException initCause

List of usage examples for java.lang RuntimeException initCause

Introduction

In this page you can find the example usage for java.lang RuntimeException initCause.

Prototype

public synchronized Throwable initCause(Throwable cause) 

Source Link

Document

Initializes the cause of this throwable to the specified value.

Usage

From source file:com.sample.common.util.AssertUtil.java

public static void assertNotNull(Object object, RuntimeException cause) {
    if (object == null) {
        cause.initCause(cause.getCause());
        throw cause;
    }//www.j  av a 2 s.  c o  m
}

From source file:org.bytesoft.openjtcc.supports.spring.NativeCompensableProxy.java

@SuppressWarnings({ "rawtypes", "unchecked" })
protected Object invokeBizMethod(Method method, Object[] args) throws Throwable {
    NativeCompensableSynchronization sync = new NativeCompensableSynchronization(this.facade);
    sync.setTransactionManager(this.transactionManager);
    TransactionManagerImpl txManager = (TransactionManagerImpl) this.transactionManager;
    try {// w w w. ja va  2  s .  co  m
        txManager.registerSynchronization(sync);

        return method.invoke(this.target, args);
    } catch (IllegalAccessException ex) {
        RuntimeException rex = new RuntimeException();
        rex.initCause(ex);
        throw rex;
    } catch (InvocationTargetException ex) {
        throw ex.getTargetException();
    } finally {
        txManager.unRegisterSynchronization(sync);
    }
}

From source file:org.bytesoft.openjtcc.supports.spring.NativeCompensableProxy.java

public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    if (Object.class.equals(method.getDeclaringClass())) {
        return method.invoke(this.target, args);
    }/*from  w  w  w .  j av  a 2 s. co m*/

    try {
        if (Compensable.class.equals(method.getDeclaringClass())) {
            return method.invoke(this.target, args);
        } else if (BeanNameAware.class.equals(method.getDeclaringClass())) {
            return method.invoke(this, args);
        }
    } catch (IllegalAccessException ex) {
        RuntimeException rex = new RuntimeException();
        rex.initCause(ex);
        throw rex;
    } catch (InvocationTargetException ex) {
        throw ex.getTargetException();
    }

    return this.invokeBizMethod(method, args);
}

From source file:at.ac.univie.isc.asio.insight.VndErrorTest.java

@Test(timeout = 1_000L)
public void do_not_fail_on_circular_causal_chain() throws Exception {
    final RuntimeException top = new RuntimeException("top");
    final RuntimeException circular = new RuntimeException("circular");
    top.initCause(circular);
    circular.initCause(top);/*from   w ww . ja  va  2 s .  co m*/
    VndError.from(top, Correlation.valueOf("none"), -1L, true);
}

From source file:net.sbbi.upnp.jmx.UPNPMBeanService.java

private String generateServiceId(ObjectName mbeanName) {
    try {//from w w w.  j a v a2  s  . c  om
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        // the uuid is based on the device type, the internal id
        // and the host name
        md5.update(mbeanName.toString().getBytes());
        StringBuffer hexString = new StringBuffer();
        byte[] digest = md5.digest();
        for (int i = 0; i < digest.length; i++) {
            hexString.append(Integer.toHexString(0xFF & digest[i]));
        }
        return hexString.toString().toUpperCase();
    } catch (Exception ex) {
        RuntimeException runTimeEx = new RuntimeException(
                "Unexpected error during MD5 hash creation, check your JRE");
        runTimeEx.initCause(ex);
        throw runTimeEx;
    }
}

From source file:com.opengamma.util.rest.ExceptionThrowingClientFilter.java

@Override
public ClientResponse handle(final ClientRequest cr) throws ClientHandlerException {
    ClientResponse response = getNext().handle(cr);
    if (response.getStatus() < 300) {
        return response; // normal valid response
    }/*from w  w w.ja v  a 2 s.  co  m*/
    MultivaluedMap<String, String> headers = response.getHeaders();
    String exType = headers.getFirst(EXCEPTION_TYPE);
    String exMsg = headers.getFirst(EXCEPTION_MESSAGE);
    if (exMsg == null) {
        exMsg = headers.getFirst(EXCEPTION_POINT);
    }
    UniformInterfaceException uiex;
    if (response.getStatus() == 404) {
        uiex = new UniformInterfaceException404NotFound(response, true);
    } else if (response.getStatus() == 204) {
        uiex = new UniformInterfaceException204NoContent(response, true);
    } else {
        uiex = new UniformInterfaceException(response, true);
    }
    if (exType == null) {
        throw uiex; // standard UniformInterfaceException as we have nothing to add
    }
    RuntimeException exception;
    try {
        Class<? extends RuntimeException> cls = Thread.currentThread().getContextClassLoader().loadClass(exType)
                .asSubclass(RuntimeException.class);
        exception = cls.getConstructor(String.class)
                .newInstance("Server threw exception: " + StringUtils.defaultString(exMsg));
    } catch (Exception ex) {
        // unable to create transparently, so use standard exception
        exception = new OpenGammaRuntimeException(
                "Server threw exception: " + exType + ": " + StringUtils.defaultString(exMsg));
    }
    exception.initCause(uiex);
    throw exception; // transparently throw exception as seen on the server
}

From source file:com.swater.meimeng.activity.oomimg.ImageCache.java

/**
 * Gets an instance of AndroidHttpClient if the devices has it (it was introduced in 2.2), or
 * falls back on a http client that should work reasonably well.
 *
 * @return a working instance of an HttpClient
 *///from www.jav a2s . com
private HttpClient getHttpClient() {
    HttpClient ahc;
    try {
        final Class<?> ahcClass = Class.forName("android.net.http.AndroidHttpClient");
        final Method newInstance = ahcClass.getMethod("newInstance", String.class);
        ahc = (HttpClient) newInstance.invoke(null, "ImageCache");

    } catch (final ClassNotFoundException e) {
        DefaultHttpClient dhc = new DefaultHttpClient();
        final HttpParams params = dhc.getParams();
        dhc = null;

        params.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 20 * 1000);

        final SchemeRegistry registry = new SchemeRegistry();
        registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
        registry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));

        final ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager(params, registry);
        ahc = new DefaultHttpClient(manager, params);

    } catch (final NoSuchMethodException e) {

        final RuntimeException re = new RuntimeException("Programming error");
        re.initCause(e);
        throw re;

    } catch (final IllegalAccessException e) {
        final RuntimeException re = new RuntimeException("Programming error");
        re.initCause(e);
        throw re;

    } catch (final InvocationTargetException e) {
        final RuntimeException re = new RuntimeException("Programming error");
        re.initCause(e);
        throw re;
    }
    return ahc;
}

From source file:edu.ksu.cis.indus.tools.slicer.SlicerConfiguration.java

/**
 * Sets up the nature of ready dependence.
 * //ww w.j  ava2 s.  c o  m
 * @param nature of ready dependence.
 */
private void setupNatureOfReadyDep(final Comparable<?> nature) {
    final Class<? extends ReadyDAv1> _clazz = getReadyDAClass(nature);

    try {
        final Set<IDependencyAnalysis<?, ?, ?, ?, ?, ?>> _temp = new HashSet<IDependencyAnalysis<?, ?, ?, ?, ?, ?>>();

        if (SliceType.FORWARD_SLICE.equals(getSliceType())) {
            _temp.add((IDependencyAnalysis) _clazz.getMethod("getForwardReadyDA", (Class[]) null).invoke(null,
                    (Object[]) null));
        } else if (SliceType.BACKWARD_SLICE.equals(getSliceType())) {
            _temp.add((IDependencyAnalysis) _clazz.getMethod("getBackwardReadyDA", (Class[]) null).invoke(null,
                    (Object[]) null));
        } else if (SliceType.COMPLETE_SLICE.equals(getSliceType())) {
            _temp.add((IDependencyAnalysis) _clazz.getMethod("getBackwardReadyDA", (Class[]) null).invoke(null,
                    (Object[]) null));
            _temp.add((IDependencyAnalysis) _clazz.getMethod("getForwardReadyDA", (Class[]) null).invoke(null,
                    (Object[]) null));
        } else {
            final String _msg = "Illegal slice type :" + _clazz.toString() + " : " + getSliceType();
            LOGGER.error("setupNatureOfReadyDep" + "() -  : " + _msg);
            throw new IllegalStateException(_msg);
        }
        id2dependencyAnalyses.put(IDependencyAnalysis.DependenceSort.READY_DA, _temp);
    } catch (final NoSuchMethodException _e) {
        final String _msg = "Dependence analysis does not provide getForwardReadyDA() and/or getBackwardReadyDA() :"
                + _clazz;
        LOGGER.error("setupNatureOfReadyDep() -  : " + _msg);

        final RuntimeException _runtimeException = new RuntimeException(_msg);
        _runtimeException.initCause(_e);
        throw _runtimeException;
    } catch (final IllegalArgumentException _e) {
        final String _msg = "Dependence analysis does not provide static zero-parameter versions of "
                + "getForwardReadyDA() and/or getBackwardReadyDA() : " + _clazz;
        LOGGER.error("setupNatureOfReadyDep() -  : " + _msg);
        throw _e;
    } catch (final SecurityException _e) {
        final String _msg = "Insufficient permission to access specified ready dependence analysis class : "
                + _clazz;
        LOGGER.error("setupNatureOfReadyDep() -  : " + _msg);

        final RuntimeException _runtimeException = new RuntimeException(_msg);
        _runtimeException.initCause(_e);
        throw _runtimeException;
    } catch (final IllegalAccessException _e) {
        final String _msg = "Dependence analysis does not provide publicly accessible versions of  "
                + "getForwardReadyDA() and/or getBackwardReadyDA() : " + _clazz;
        LOGGER.error("setupNatureOfReadyDep() -  : " + _msg);

        final RuntimeException _runtimeException = new RuntimeException(_msg);
        _runtimeException.initCause(_e);
        throw _runtimeException;
    } catch (final InvocationTargetException _e) {
        final String _msg = "getForwardReadyDA() and/or getBackwardReadyDA() threw an exception : " + _clazz;
        LOGGER.error("setupNatureOfReadyDep() -  : " + _msg);

        final RuntimeException _runtimeException = new RuntimeException(_msg);
        _runtimeException.initCause(_e);
        throw _runtimeException;
    }
}

From source file:edu.ksu.cis.indus.tools.slicer.SlicerConfiguration.java

/**
 * Sets up interference dependence./* w  w  w  .  j a va2  s .com*/
 * 
 * @throws IllegalStateException when interference dependence cannot be setup.
 */
private void setupInterferenceDependence() {
    final IDependencyAnalysis.DependenceSort _id = IDependencyAnalysis.DependenceSort.INTERFERENCE_DA;

    if (isInterferenceDepAnalysisUsed()) {
        dependencesToUse.add(_id);

        final Comparable<?> _property = getNatureOfInterferenceDepAnalysis();
        final Class<? extends InterferenceDAv1> _clazz;

        if (SYMBOL_AND_EQUIVCLS_BASED_INFO.equals(_property)) {
            _clazz = InterferenceDAv3.class;
        } else if (EQUIVALENCE_CLASS_BASED_INFO.equals(_property)) {
            _clazz = InterferenceDAv2.class;
        } else if (TYPE_BASED_INFO.equals(_property)) {
            _clazz = InterferenceDAv1.class;
        } else {
            final String _msg = "Interference dependence could not be configured due to illegal "
                    + "interference dependence nature.";
            LOGGER.error("setupInterferenceDependence() -  : " + _msg);
            throw new IllegalStateException(_msg);
        }

        final Constructor<? extends InterferenceDAv1> _constructor;

        try {
            _constructor = _clazz.getConstructor((Class[]) null);
            final InterferenceDAv1 _newInstance = _constructor.newInstance((Object[]) null);
            id2dependencyAnalyses.put(IDependencyAnalysis.DependenceSort.INTERFERENCE_DA,
                    Collections.<IDependencyAnalysis<?, ?, ?, ?, ?, ?>>singleton(_newInstance));
        } catch (final NoSuchMethodException _e) {
            final String _msg = "Dependence analysis does not provide zero parameter constructor :" + _clazz;
            LOGGER.error("setupInterferenceDependence() -  : " + _msg);

            final RuntimeException _runtimeException = new RuntimeException(_msg);
            _runtimeException.initCause(_e);
            throw _runtimeException;
        } catch (final IllegalArgumentException _e) {
            final String _msg = "Dependence analysis does not provide zero-parameter constructor : " + _clazz;
            LOGGER.error("setupInterferenceDependence() -  : " + _msg);
            throw _e;
        } catch (final SecurityException _e) {
            final String _msg = "Insufficient permission to access specified dependence analysis class : "
                    + _clazz;
            LOGGER.error("setupInterferenceDependence() -  : " + _msg);

            final RuntimeException _runtimeException = new RuntimeException(_msg);
            _runtimeException.initCause(_e);
            throw _runtimeException;
        } catch (final IllegalAccessException _e) {
            final String _msg = "Dependence analysis does not provide publicly accessible constructors : "
                    + _clazz;
            LOGGER.error("setupInterferenceDependence() -  : " + _msg);

            final RuntimeException _runtimeException = new RuntimeException(_msg);
            _runtimeException.initCause(_e);
            throw _runtimeException;
        } catch (final InvocationTargetException _e) {
            final String _msg = "constructor threw an exception : " + _clazz;
            LOGGER.error("setupInterferenceDependence() -  : " + _msg);

            final RuntimeException _runtimeException = new RuntimeException(_msg);
            _runtimeException.initCause(_e);
            throw _runtimeException;
        } catch (final InstantiationException _e) {
            final String _msg = "Exception while instantiating the analysis : " + _clazz;
            LOGGER.error("setupInterferenceDependence() -  : " + _msg);

            final RuntimeException _runtimeException = new RuntimeException(_msg);
            _runtimeException.initCause(_e);
            throw _runtimeException;
        }

        for (final Iterator<? extends IDependencyAnalysis<?, ?, ?, ?, ?, ?>> _i = id2dependencyAnalyses
                .get(IDependencyAnalysis.DependenceSort.INTERFERENCE_DA).iterator(); _i.hasNext();) {
            final InterferenceDAv1 _ida = (InterferenceDAv1) _i.next();
            _ida.setUseOFA(isOFAUsedForInterference());
        }
    } else {
        dependencesToUse.remove(_id);
        id2dependencyAnalyses.remove(_id);
    }
}

From source file:ome.tools.hibernate.QueryBuilder.java

private Query __query(Session session, boolean usefilter) {

    if (usefilter) {
        filterNow();// w  w  w  .  ja v a  2 s .  c  om
    }

    Query q = null;
    try {
        final String s = queryString();
        if (sqlQuery) {
            // ticket:9435 - in order to allow updates with raw
            // SQL we will unwrap the session. This is the only
            // location that is doing such unwrapping.
            // Also see ticket:9496 about deleting rdefs.
            if (s.startsWith("update") || s.startsWith("delete")) {
                if (session instanceof Advised) {
                    Advised proxy = (Advised) session;
                    try {
                        session = (Session) proxy.getTargetSource().getTarget();
                    } catch (Exception e) {
                        RuntimeException rt = new RuntimeException(e);
                        rt.initCause(e);
                        throw rt;
                    }
                }
            }
            q = session.createSQLQuery(queryString());
        } else {
            q = session.createQuery(queryString());
        }
    } catch (RuntimeException rt) {
        // We're logging failed queries because the almost always point
        // to an internal exception that shouldn't be happening.
        log.warn("Failed query: " + queryString(), rt);
        throw rt;
    }

    for (String key : params.keySet()) {
        q.setParameter(key, params.get(key));
    }
    for (String key : listParams.keySet()) {
        q.setParameterList(key, listParams.get(key));
    }
    if (filter != null) {
        if (filter.limit != null) {
            q.setMaxResults(filter.limit);
        }
        if (filter.offset != null) {
            q.setFirstResult(filter.offset);
        }
    }
    return q;
}