Search in sources :

Example 21 with UndeclaredThrowableException

use of java.lang.reflect.UndeclaredThrowableException in project robovm by robovm.

the class WTInvocationHandler method main.

public static void main(String[] args) {
    WTMix mix = new WTMix();
    InvocationHandler handler = new WTInvocationHandler(mix);
    Object proxy;
    try {
        proxy = Proxy.newProxyInstance(WrappedThrow.class.getClassLoader(), new Class[] { InterfaceW1.class, InterfaceW2.class }, handler);
    } catch (IllegalArgumentException iae) {
        System.out.println("WT init failed");
        return;
    }
    InterfaceW1 if1 = (InterfaceW1) proxy;
    InterfaceW2 if2 = (InterfaceW2) proxy;
    try {
        if1.throwFunky();
        System.err.println("No exception thrown");
    } catch (UndeclaredThrowableException ute) {
        System.out.println("Got expected UTE");
    } catch (Throwable t) {
        System.err.println("Got unexpected exception: " + t);
    }
    try {
        if1.throwFunky2();
        System.err.println("No exception thrown");
    } catch (IOException ioe) {
        System.out.println("Got expected IOE");
    } catch (Throwable t) {
        System.err.println("Got unexpected exception: " + t);
    }
    try {
        if2.throwFunky2();
        System.err.println("No exception thrown");
    } catch (IOException ioe) {
        System.out.println("Got expected IOE");
    } catch (Throwable t) {
        System.err.println("Got unexpected exception: " + t);
    }
    /*
         * Throw exceptions, walking down the hierarchy.
         */
    try {
        if1.throwException();
        System.err.println("No exception thrown");
    } catch (UndeclaredThrowableException ute) {
        System.out.println("Got expected UTE");
    } catch (Throwable t) {
        System.err.println("Got unexpected exception: " + t);
    }
    try {
        if1.throwBase();
        System.err.println("No exception thrown");
    } catch (UndeclaredThrowableException ute) {
        System.out.println("Got expected UTE");
    } catch (Throwable t) {
        System.err.println("Got unexpected exception: " + t);
    }
    try {
        if2.throwSub();
        System.err.println("No exception thrown");
    } catch (SubException se) {
        System.out.println("Got expected exception");
    } catch (Throwable t) {
        System.err.println("Got unexpected exception: " + t);
    }
    try {
        if2.throwSubSub();
        System.err.println("No exception thrown");
    } catch (SubException se) {
        System.out.println("Got expected exception");
    } catch (Throwable t) {
        System.err.println("Got unexpected exception: " + t);
    }
    /*
         * Make sure that, if the class explicitly allows the base
         * class of an exception, that we still allow it.
         */
    try {
        if1.bothThrowBase();
        System.err.println("No exception thrown");
    } catch (BaseException se) {
        System.out.println("Got expected exception");
    } catch (Throwable t) {
        System.err.println("Got unexpected exception: " + t);
    }
}
Also used : IOException(java.io.IOException) InvocationHandler(java.lang.reflect.InvocationHandler) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException)

Example 22 with UndeclaredThrowableException

use of java.lang.reflect.UndeclaredThrowableException in project spring-framework by spring-projects.

the class ApplicationListenerMethodAdapter method doInvoke.

/**
	 * Invoke the event listener method with the given argument values.
	 */
protected Object doInvoke(Object... args) {
    Object bean = getTargetBean();
    ReflectionUtils.makeAccessible(this.bridgedMethod);
    try {
        return this.bridgedMethod.invoke(bean, args);
    } catch (IllegalArgumentException ex) {
        assertTargetBean(this.bridgedMethod, bean, args);
        throw new IllegalStateException(getInvocationErrorMessage(bean, ex.getMessage(), args), ex);
    } catch (IllegalAccessException ex) {
        throw new IllegalStateException(getInvocationErrorMessage(bean, ex.getMessage(), args), ex);
    } catch (InvocationTargetException ex) {
        // Throw underlying exception
        Throwable targetException = ex.getTargetException();
        if (targetException instanceof RuntimeException) {
            throw (RuntimeException) targetException;
        } else {
            String msg = getInvocationErrorMessage(bean, "Failed to invoke event listener method", args);
            throw new UndeclaredThrowableException(targetException, msg);
        }
    }
}
Also used : UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 23 with UndeclaredThrowableException

use of java.lang.reflect.UndeclaredThrowableException in project spring-framework by spring-projects.

the class ScheduledMethodRunnable method run.

@Override
public void run() {
    try {
        ReflectionUtils.makeAccessible(this.method);
        this.method.invoke(this.target);
    } catch (InvocationTargetException ex) {
        ReflectionUtils.rethrowRuntimeException(ex.getTargetException());
    } catch (IllegalAccessException ex) {
        throw new UndeclaredThrowableException(ex);
    }
}
Also used : UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 24 with UndeclaredThrowableException

use of java.lang.reflect.UndeclaredThrowableException in project spring-framework by spring-projects.

the class AbstractAopProxyTests method testUndeclaredCheckedException.

/**
	 * An interceptor throws a checked exception not on the method signature.
	 * For efficiency, we don't bother unifying java.lang.reflect and
	 * org.springframework.cglib UndeclaredThrowableException
	 */
@Test
public void testUndeclaredCheckedException() throws Throwable {
    final Exception unexpectedException = new Exception();
    // Test return value
    MethodInterceptor mi = new MethodInterceptor() {

        @Override
        public Object invoke(MethodInvocation invocation) throws Throwable {
            throw unexpectedException;
        }
    };
    AdvisedSupport pc = new AdvisedSupport(ITestBean.class);
    pc.addAdvice(ExposeInvocationInterceptor.INSTANCE);
    pc.addAdvice(mi);
    // We don't care about the object
    pc.setTarget(new TestBean());
    AopProxy aop = createAopProxy(pc);
    ITestBean tb = (ITestBean) aop.getProxy();
    try {
        // Note: exception param below isn't used
        tb.getAge();
        fail("Should have wrapped exception raised by interceptor");
    } catch (UndeclaredThrowableException thrown) {
        assertEquals("exception matches", unexpectedException, thrown.getUndeclaredThrowable());
    } catch (Exception ex) {
        ex.printStackTrace();
        fail("Didn't expect exception: " + ex);
    }
}
Also used : ITestBean(org.springframework.tests.sample.beans.ITestBean) MethodInterceptor(org.aopalliance.intercept.MethodInterceptor) ITestBean(org.springframework.tests.sample.beans.ITestBean) TestBean(org.springframework.tests.sample.beans.TestBean) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) MethodInvocation(org.aopalliance.intercept.MethodInvocation) FileNotFoundException(java.io.FileNotFoundException) SQLException(java.sql.SQLException) MarshalException(java.rmi.MarshalException) IOException(java.io.IOException) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) LockedException(test.mixin.LockedException) Test(org.junit.Test)

Example 25 with UndeclaredThrowableException

use of java.lang.reflect.UndeclaredThrowableException in project jstorm by alibaba.

the class JstormMaster method publishContainerStartEvent.

private static void publishContainerStartEvent(final TimelineClient timelineClient, Container container, String domainId, UserGroupInformation ugi) {
    final TimelineEntity entity = new TimelineEntity();
    entity.setEntityId(container.getId().toString());
    entity.setEntityType(DSEntity.DS_CONTAINER.toString());
    entity.setDomainId(domainId);
    entity.addPrimaryFilter(JOYConstants.USER, ugi.getShortUserName());
    TimelineEvent event = new TimelineEvent();
    event.setTimestamp(System.currentTimeMillis());
    event.setEventType(DSEvent.DS_CONTAINER_START.toString());
    event.addEventInfo(JOYConstants.NODE, container.getNodeId().toString());
    event.addEventInfo(JOYConstants.RESOURCES, container.getResource().toString());
    entity.addEvent(event);
    try {
        ugi.doAs(new PrivilegedExceptionAction<TimelinePutResponse>() {

            @Override
            public TimelinePutResponse run() throws Exception {
                return timelineClient.putEntities(entity);
            }
        });
    } catch (Exception e) {
        LOG.error("Container start event could not be published for " + container.getId().toString(), e instanceof UndeclaredThrowableException ? e.getCause() : e);
    }
}
Also used : TimelineEvent(org.apache.hadoop.yarn.api.records.timeline.TimelineEvent) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) TimelinePutResponse(org.apache.hadoop.yarn.api.records.timeline.TimelinePutResponse) TimelineEntity(org.apache.hadoop.yarn.api.records.timeline.TimelineEntity) ParseException(org.apache.commons.cli.ParseException) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) IOException(java.io.IOException) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException)

Aggregations

UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)121 IOException (java.io.IOException)36 InvocationTargetException (java.lang.reflect.InvocationTargetException)14 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)14 Test (org.junit.Test)12 BufferedReader (java.io.BufferedReader)10 InputStreamReader (java.io.InputStreamReader)10 ServerSocket (java.net.ServerSocket)10 Socket (java.net.Socket)9 PollStatus (org.opennms.netmgt.poller.PollStatus)9 HashMap (java.util.HashMap)8 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)7 AuthorizationException (org.apache.hadoop.security.authorize.AuthorizationException)7 BadRequestException (org.apache.hadoop.yarn.webapp.BadRequestException)7 Method (java.lang.reflect.Method)6 AccessControlException (java.security.AccessControlException)6 SQLException (java.sql.SQLException)6 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)6