diff --git a/impl/src/main/java/org/jboss/weld/bean/InterceptorImpl.java b/impl/src/main/java/org/jboss/weld/bean/InterceptorImpl.java index b4e74537354..9fc1ce9994a 100644 --- a/impl/src/main/java/org/jboss/weld/bean/InterceptorImpl.java +++ b/impl/src/main/java/org/jboss/weld/bean/InterceptorImpl.java @@ -88,6 +88,8 @@ public Object intercept(InterceptionType type, T instance, InvocationContext ctx Collection> invocations = new ArrayList>(); invocations.add(new InterceptorInvocation(instance, interceptorMetadata, interceptionType)); return new SimpleInterceptionChain(invocations, instance, ctx.getMethod()).invokeNextInterceptor(ctx); + } catch (RuntimeException e) { + throw e; } catch (Throwable e) { throw new WeldException(e); } diff --git a/tests-arquillian/src/test/java/org/jboss/weld/tests/interceptors/exceptions/Foo.java b/tests-arquillian/src/test/java/org/jboss/weld/tests/interceptors/exceptions/Foo.java new file mode 100644 index 00000000000..283a825f2fb --- /dev/null +++ b/tests-arquillian/src/test/java/org/jboss/weld/tests/interceptors/exceptions/Foo.java @@ -0,0 +1,19 @@ +package org.jboss.weld.tests.interceptors.exceptions; + +import org.jboss.weld.exceptions.WeldException; + +/** + * + */ +@FooBinding +public class Foo { + + public void throwCheckedException() throws FooCheckedException { + throw new FooCheckedException(); + } + + public void throwUncheckedException() throws FooUncheckedException { + throw new FooUncheckedException(); + } + +} diff --git a/tests-arquillian/src/test/java/org/jboss/weld/tests/interceptors/exceptions/FooBinding.java b/tests-arquillian/src/test/java/org/jboss/weld/tests/interceptors/exceptions/FooBinding.java new file mode 100644 index 00000000000..3a50de83c4a --- /dev/null +++ b/tests-arquillian/src/test/java/org/jboss/weld/tests/interceptors/exceptions/FooBinding.java @@ -0,0 +1,18 @@ +package org.jboss.weld.tests.interceptors.exceptions; + +import javax.interceptor.InterceptorBinding; +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * + */ +@Inherited +@InterceptorBinding +@Target({ElementType.TYPE, ElementType.METHOD}) +@Retention(RetentionPolicy.RUNTIME) +public @interface FooBinding { +} diff --git a/tests-arquillian/src/test/java/org/jboss/weld/tests/interceptors/exceptions/FooCheckedException.java b/tests-arquillian/src/test/java/org/jboss/weld/tests/interceptors/exceptions/FooCheckedException.java new file mode 100644 index 00000000000..b534bf7c6f2 --- /dev/null +++ b/tests-arquillian/src/test/java/org/jboss/weld/tests/interceptors/exceptions/FooCheckedException.java @@ -0,0 +1,7 @@ +package org.jboss.weld.tests.interceptors.exceptions; + +/** + * + */ +public class FooCheckedException extends Exception { +} diff --git a/tests-arquillian/src/test/java/org/jboss/weld/tests/interceptors/exceptions/FooUncheckedException.java b/tests-arquillian/src/test/java/org/jboss/weld/tests/interceptors/exceptions/FooUncheckedException.java new file mode 100644 index 00000000000..7cf0f37efdf --- /dev/null +++ b/tests-arquillian/src/test/java/org/jboss/weld/tests/interceptors/exceptions/FooUncheckedException.java @@ -0,0 +1,7 @@ +package org.jboss.weld.tests.interceptors.exceptions; + +/** + * + */ +public class FooUncheckedException extends RuntimeException { +} diff --git a/tests-arquillian/src/test/java/org/jboss/weld/tests/interceptors/exceptions/InterceptorExceptionWrappingTest.java b/tests-arquillian/src/test/java/org/jboss/weld/tests/interceptors/exceptions/InterceptorExceptionWrappingTest.java new file mode 100644 index 00000000000..7828480c894 --- /dev/null +++ b/tests-arquillian/src/test/java/org/jboss/weld/tests/interceptors/exceptions/InterceptorExceptionWrappingTest.java @@ -0,0 +1,32 @@ +package org.jboss.weld.tests.interceptors.exceptions; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.shrinkwrap.api.Archive; +import org.jboss.shrinkwrap.api.BeanArchive; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * author Marko Luksa + */ +@RunWith(Arquillian.class) +public class InterceptorExceptionWrappingTest { + @Deployment + public static Archive deploy() { + return ShrinkWrap.create(BeanArchive.class) + .intercept(MyInterceptor.class) + .addPackage(InterceptorExceptionWrappingTest.class.getPackage()); + } + + @Test(expected = FooCheckedException.class) + public void testCheckedExceptionIsNotWrapped(Foo foo) throws Exception { + foo.throwCheckedException(); + } + + @Test(expected = FooUncheckedException.class) + public void testUncheckedExceptionIsNotWrapped(Foo foo) throws Exception { + foo.throwUncheckedException(); + } +} diff --git a/tests-arquillian/src/test/java/org/jboss/weld/tests/interceptors/exceptions/MyInterceptor.java b/tests-arquillian/src/test/java/org/jboss/weld/tests/interceptors/exceptions/MyInterceptor.java new file mode 100644 index 00000000000..a177f8fd750 --- /dev/null +++ b/tests-arquillian/src/test/java/org/jboss/weld/tests/interceptors/exceptions/MyInterceptor.java @@ -0,0 +1,19 @@ +package org.jboss.weld.tests.interceptors.exceptions; + +import javax.interceptor.AroundInvoke; +import javax.interceptor.Interceptor; +import javax.interceptor.InvocationContext; + +/** + * + */ +@Interceptor +@FooBinding +public class MyInterceptor { + + @AroundInvoke + public Object aroundInvoke(final InvocationContext invocation) throws Exception { + return invocation.proceed(); + } + +}