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.brienwheeler.lib.test.stepper.SteppableThreadTest.java

@Test
public void testJoinTimeout() {
    SteppableThread stepper = new SteppableOneStep();
    ReflectionTestUtils.setField(stepper, "joinDelay", 10L);
    stepper.start();//  w ww . ja  v  a  2s . c om

    try {
        stepper.releaseAndJoin();
        Assert.fail();
    } catch (RuntimeException e) {
        Assert.assertEquals(TimeoutException.class, e.getCause().getClass());
    }

    ReflectionTestUtils.setField(stepper, "joinDelay", 10000L);
    stepper.waitDone();
    stepper.releaseAndJoin();
}

From source file:org.mybatis.spring.MyBatisExceptionTranslator.java

/**
 * {@inheritDoc}/*from www  .j a v  a2  s. c  o m*/
 */
@Override
public DataAccessException translateExceptionIfPossible(RuntimeException e) {
    if (e instanceof PersistenceException) {
        // Batch exceptions come inside another PersistenceException
        // recursion has a risk of infinite loop so better make another if
        if (e.getCause() instanceof PersistenceException) {
            e = (PersistenceException) e.getCause();
        }
        if (e.getCause() instanceof SQLException) {
            this.initExceptionTranslator();
            return this.exceptionTranslator.translate(e.getMessage() + "\n", null, (SQLException) e.getCause());
        } else if (e.getCause() instanceof TransactionException) {
            throw (TransactionException) e.getCause();
        }
        return new MyBatisSystemException(e);
    }
    return null;
}

From source file:org.apache.qpid.server.virtualhost.VirtualHostImplTest.java

/**
 * Tests that specifying custom routing keys for a queue in the configuration file results in failure
 * to create the vhost (since this is illegal, only queue names are used with the default exchange)
 *///from w w w .  ja va2 s .  co  m
public void testSpecifyingCustomBindingForDefaultExchangeThrowsException() throws Exception {
    final String queueName = getName();
    final String customBinding = "custom-binding";
    File config = writeConfigFile(queueName, queueName, null, false, new String[] { customBinding });

    try {
        createVirtualHost(queueName, config);
        fail("virtualhost creation should have failed due to illegal configuration");
    } catch (RuntimeException e) {
        assertNotNull(e.getCause());

        assertEquals(ConfigurationException.class, e.getCause().getClass());

        Throwable configException = e.getCause();
        assertEquals(
                "Illegal attempt to bind queue '" + queueName
                        + "' to the default exchange with a key other than the queue name: " + customBinding,
                configException.getMessage());
    }
}

From source file:de.micromata.genome.util.bean.PropertyAttrSetterGetter.java

@Override
public void set(BEAN bean, VAL value) {
    init(bean);//from   w  w  w .j  a  va  2  s. c o m
    try {
        propDescriptor.getWriteMethod().invoke(bean, new Object[] { value });
    } catch (RuntimeException ex) { // NOSONAR "Illegal Catch" framework
        throw ex;// NOSONAR "Illegal Catch" framework
    } catch (InvocationTargetException ex) {
        Throwable nex = ex.getCause();
        if (nex instanceof RuntimeException) {
            throw (RuntimeException) nex; // NOSONAR "Illegal Catch" framework
        }
        throw new RuntimeException(nex); // NOSONAR "Illegal Catch" framework
    } catch (Exception ex) { // NOSONAR "Illegal Catch" framework
        throw new RuntimeException(ex); // NOSONAR "Illegal Catch" framework
    }
}

From source file:org.sakaiproject.site.impl.test.SiteAliasCleanupNotificationActionTest.java

public void testRaisesCheckedExceptionsInUncheckedExceptionsIfSoConfigured() throws PermissionException {
    cleanupAction.setPropagateExceptions(true);
    expectInit();//from   ww  w  .  jav a2s .com
    final String resourceId = "/entity/id";
    final PermissionException failure = new PermissionException("user-123", SiteService.SECURE_REMOVE_SITE,
            resourceId);
    checking(new Expectations() {
        {
            allowing(inboundEvent).getResource();
            will(returnValue(resourceId));
            one(aliasService).removeTargetAliases(resourceId);
            will(throwException(failure));
        }
    });

    cleanupAction.init();
    try {
        cleanupAction.notify(inboundNotification, inboundEvent);
        fail("Should have raised an unchecked exception wrapping the checked exception indicating failure to delete aliases");
    } catch (RuntimeException e) {
        assertSame("Didn't wrap exception representing failure to delete aliases", failure, e.getCause());
    }
}

From source file:de.micromata.genome.util.bean.PropertyAttrSetterGetter.java

@Override
@SuppressWarnings("unchecked")
public VAL get(BEAN bean) {
    init(bean);/*from  w ww .  j a  v a2  s.com*/
    try {
        return (VAL) propDescriptor.getReadMethod().invoke(bean, ArrayUtils.EMPTY_OBJECT_ARRAY);
    } catch (RuntimeException ex) {// NOSONAR "Illegal Catch" framework 
        throw ex;// NOSONAR "Illegal Catch" framework
    } catch (InvocationTargetException ex) {
        Throwable nex = ex.getCause();
        if (nex instanceof RuntimeException) { // NOSONAR "Illegal Catch" framework
            throw (RuntimeException) nex; // NOSONAR "Illegal Catch" framework
        }
        throw new RuntimeException(nex);// NOSONAR "Illegal Catch" framework
    } catch (Exception ex) {// NOSONAR "Illegal Catch" framework
        throw new RuntimeException(ex);// NOSONAR "Illegal Catch" framework
    }
}

From source file:com.brienwheeler.lib.test.stepper.SteppableThreadTest.java

@Test
public void testWaitDoneBrokenBarrier() throws InterruptedException {
    SteppableThread stepper = new SteppableOneStep();

    interruptInWait(stepper, TestMode.WAITDONE);

    try {/*from   w  ww  .j a v a 2s.c om*/
        stepper.waitDone();
        Assert.fail();
    } catch (RuntimeException e) {
        Assert.assertEquals(BrokenBarrierException.class, e.getCause().getClass());
    }

    ((CyclicBarrier) ReflectionTestUtils.getField(stepper, "stepDone")).reset();
    stepper.start();
    stepper.releaseAndWaitDone();
    stepper.releaseAndJoin();
}

From source file:com.brienwheeler.lib.test.stepper.SteppableThreadTest.java

@Test
public void testReleaseBrokenBarrier() throws InterruptedException {
    CountDownLatch latch = new CountDownLatch(1);
    SteppableThread latchStepper = new SteppableWaitForLatch(latch);

    interruptInWait(latchStepper, TestMode.RELEASE);

    try {/*w w  w . j a va2 s. c om*/
        latchStepper.release();
        Assert.fail();
    } catch (RuntimeException e) {
        Assert.assertEquals(BrokenBarrierException.class, e.getCause().getClass());
    }

    ((CyclicBarrier) ReflectionTestUtils.getField(latchStepper, "stepStart")).reset();
    latchStepper.start();
    latch.countDown();
    latchStepper.releaseAndJoin();
}

From source file:com.weibo.api.motan.filter.ServiceMockFilter.java

@Override
public Response filter(Caller<?> caller, Request request) {

    // Do nothing when mock is empty.
    String mockServiceName = caller.getUrl().getParameter(URLParamType.mock.getName());
    if (StringUtils.isEmpty(mockServiceName) || "false".equals(mockServiceName)) {
        return caller.call(request);
    }/*  w  w w  .j  a v  a  2  s . c o m*/

    MockInfo info = getServiceStat(caller.getUrl());

    DefaultResponse response = new DefaultResponse();

    if (mockServiceName.startsWith(RETURN_PREFIX)) {
        String value = mockServiceName.substring(RETURN_PREFIX.length());
        try {
            info.callNum.addAndGet(1);

            long sleepTime = caclSleepTime(info);
            Thread.sleep(sleepTime);

            response.setValue(parseMockValue(value));
        } catch (RuntimeException e) {
            if (e.getCause() != null) {
                response.setException(new MotanBizException("mock service call process error", e.getCause()));
            } else {
                response.setException(new MotanBizException("mock service call process error", e));
            }
        } catch (Exception e) {
            throw new IllegalStateException(
                    "Illegal mock json value in <motan:service ... mock=\"" + mockServiceName + "\" />");
        }
    } else {
        try {
            Class<?> mockClass = isDefault(mockServiceName)
                    ? ReflectUtil.forName(caller.getInterface().getName() + "Mock")
                    : ReflectUtil.forName(mockServiceName);
            if (!caller.getInterface().isAssignableFrom(mockClass)) {
                throw new MotanFrameworkException("The mock implemention class " + mockClass.getName()
                        + " not implement interface " + caller.getInterface().getName());
            }
            try {
                mockClass.getConstructor();
            } catch (NoSuchMethodException e) {
                throw new IllegalStateException("No such empty constructor \"public "
                        + mockClass.getSimpleName() + "()\" in mock implemention class " + mockClass.getName());
            }

            String methodDesc = ReflectUtil.getMethodDesc(request.getMethodName(), request.getParamtersDesc());

            Method[] methods = mockClass.getMethods();

            boolean invoke = false;
            for (Method method : methods) {
                if (methodDesc.equals(ReflectUtil.getMethodDesc(method))) {
                    Object value = invoke(mockClass.newInstance(), method, request.getArguments(), info);
                    response.setValue(value);
                    invoke = true;
                    break;
                }
            }
            if (!invoke) {
                throw new MotanFrameworkException("Mock method is not found." + methodDesc);
            }

        } catch (ClassNotFoundException e) {
            throw new MotanFrameworkException("Mock service is not found."
                    + (isDefault(mockServiceName) ? caller.getInterface().getName() + "Mock"
                            : mockServiceName));
        } catch (Exception e) {
            if (e.getCause() != null) {
                response.setException(new MotanBizException("mock service call process error", e.getCause()));
            } else {
                response.setException(new MotanBizException("mock service call process error", e));
            }
        }
    }
    return response;
}

From source file:org.apache.metron.integration.components.FluxTopologyComponent.java

@Override
public void stop() {
    if (stormCluster != null) {
        try {//from w  w  w .java2 s .c  o m
            try {
                // Kill the topology directly instead of sitting through the wait period
                killTopology();
                stormCluster.shutdown();
            } catch (IllegalStateException ise) {
                if (!(ise.getMessage().contains("It took over")
                        && ise.getMessage().contains("to shut down slot"))) {
                    throw ise;
                } else {
                    LOG.error("Attempting to assassinate slots");
                    assassinateSlots();
                    LOG.error("Storm slots didn't shut down entirely cleanly *sigh*.  "
                            + "I gave them the old one-two-skadoo and killed the slots with prejudice.  "
                            + "If tests fail, we'll have to find a better way of killing them.", ise);
                }
            } catch (RuntimeException re) {
                if (re.getCause() instanceof TProtocolException) {
                    //let this go, it's some intermittent weirdness.
                } else {
                    throw re;
                }
            }
        } catch (Throwable t) {
            LOG.error(t.getMessage(), t);
        } finally {
            cleanupWorkerDir();
        }
    }
}