1212
1313import org .junit .runners .model .FrameworkMethod ;
1414
15+ import com .nordstrom .common .base .UncheckedThrow ;
16+
1517import net .bytebuddy .implementation .bind .annotation .BindingPriority ;
1618import net .bytebuddy .implementation .bind .annotation .Origin ;
1719import net .bytebuddy .implementation .bind .annotation .RuntimeType ;
@@ -43,15 +45,14 @@ private MethodInterceptor() {
4345 * @param clazz "enhanced" class upon which the method was invoked
4446 * @param method {@link Method} object for the invoked method
4547 * @param proxy call-able proxy for the intercepted method
46- * @return {@code anything} (the result of invoking the intercepted method)
4748 * @throws Exception {@code anything} (exception thrown by the intercepted method)
4849 */
4950 @ RuntimeType
5051 @ BindingPriority (1 )
51- public static Object intercept (@ Origin Class <?> clazz , @ Origin Method method , @ SuperCall Callable <?> proxy ) throws Exception {
52- Object result ;
52+ public static void intercept (@ Origin Class <?> clazz , @ Origin Method method , @ SuperCall Callable <?> proxy ) throws Exception {
5353 attachWatchers (clazz );
5454
55+ Throwable thrown = null ;
5556 FrameworkMethod member = new FrameworkMethod (method );
5657 synchronized (methodWatchers2 ) {
5758 for (MethodWatcher2 watcher : methodWatchers2 ) {
@@ -60,16 +61,20 @@ public static Object intercept(@Origin Class<?> clazz, @Origin Method method, @S
6061 }
6162
6263 try {
63- result = proxy .call ();
64+ proxy .call ();
65+ } catch (Throwable t ) {
66+ thrown = t ;
6467 } finally {
6568 synchronized (methodWatchers2 ) {
6669 for (MethodWatcher2 watcher : methodWatchers2 ) {
67- watcher .afterInvocation (member );
70+ watcher .afterInvocation (member , thrown );
6871 }
6972 }
7073 }
7174
72- return result ;
75+ if (thrown != null ) {
76+ throw UncheckedThrow .throwUnchecked (thrown );
77+ }
7378 }
7479
7580 /**
@@ -78,15 +83,13 @@ public static Object intercept(@Origin Class<?> clazz, @Origin Method method, @S
7883 * @param obj "enhanced" object upon which the method was invoked
7984 * @param method {@link Method} object for the invoked method
8085 * @param proxy call-able proxy for the intercepted method
81- * @return {@code anything} (the result of invoking the intercepted method)
8286 * @throws Exception {@code anything} (exception thrown by the intercepted method)
8387 */
8488 @ RuntimeType
8589 @ BindingPriority (2 )
86- public static Object intercept (@ This Object obj , @ Origin Method method , @ SuperCall Callable <?> proxy ) throws Exception
90+ public static void intercept (@ This Object obj , @ Origin Method method , @ SuperCall Callable <?> proxy ) throws Exception
8791 {
88- Object result ;
89-
92+ Throwable thrown = null ;
9093 FrameworkMethod member = new FrameworkMethod (method );
9194 synchronized (methodWatchers ) {
9295 for (MethodWatcher watcher : methodWatchers ) {
@@ -100,23 +103,27 @@ public static Object intercept(@This Object obj, @Origin Method method, @SuperCa
100103 }
101104
102105 try {
103- result = proxy .call ();
106+ proxy .call ();
107+ } catch (Throwable t ) {
108+ thrown = t ;
104109 } finally {
105110 synchronized (watchers ) {
106111 synchronized (methodWatchers ) {
107112 for (MethodWatcher watcher : methodWatchers ) {
108- watcher .afterInvocation (obj , member );
113+ watcher .afterInvocation (obj , member , thrown );
109114 }
110115 }
111116 synchronized (methodWatchers2 ) {
112117 for (MethodWatcher2 watcher : methodWatchers2 ) {
113- watcher .afterInvocation (obj , member );
118+ watcher .afterInvocation (obj , member , thrown );
114119 }
115120 }
116121 }
117122 }
118123
119- return result ;
124+ if (thrown != null ) {
125+ throw UncheckedThrow .throwUnchecked (thrown );
126+ }
120127 }
121128
122129 /**
0 commit comments