|
20 | 20 | import java.util.List; |
21 | 21 | import javax.annotation.Nullable; |
22 | 22 | import net.bytebuddy.asm.Advice; |
23 | | -import net.bytebuddy.asm.Advice.AssignReturned; |
24 | 23 | import net.bytebuddy.asm.Advice.AssignReturned.ToArguments.ToArgument; |
25 | 24 | import play.shaded.ahc.org.asynchttpclient.AsyncHandler; |
26 | 25 | import play.shaded.ahc.org.asynchttpclient.Request; |
@@ -56,13 +55,14 @@ public static class AdviceScope { |
56 | 55 | private final Request request; |
57 | 56 | private final Scope scope; |
58 | 57 |
|
59 | | - public AdviceScope(Context parentContext, Request request, Context context, Scope scope) { |
| 58 | + private AdviceScope(Context parentContext, Request request, Context context, Scope scope) { |
60 | 59 | this.parentContext = parentContext; |
61 | 60 | this.request = request; |
62 | | - this.context = parentContext; |
| 61 | + this.context = context; |
63 | 62 | this.scope = scope; |
64 | 63 | } |
65 | 64 |
|
| 65 | + @Nullable |
66 | 66 | public static AdviceScope start(Request request) { |
67 | 67 | Context parentContext = currentContext(); |
68 | 68 | if (!instrumenter().shouldStart(parentContext, request)) { |
@@ -91,15 +91,18 @@ public void end(@Nullable Throwable throwable) { |
91 | 91 | } |
92 | 92 | } |
93 | 93 |
|
94 | | - @AssignReturned.ToArguments(@ToArgument(value = 1, index = 1)) |
| 94 | + @Advice.AssignReturned.ToArguments(@ToArgument(value = 1, index = 1)) |
95 | 95 | @Advice.OnMethodEnter(suppress = Throwable.class) |
96 | 96 | public static Object[] methodEnter( |
97 | | - @Advice.Argument(0) Request request, @Advice.Argument(1) AsyncHandler<?> asyncHandler) { |
| 97 | + @Advice.Argument(0) Request request, |
| 98 | + @Advice.Argument(1) AsyncHandler<?> originalAsyncHandler) { |
| 99 | + // intermediate variable required for inlined advice |
| 100 | + AsyncHandler<?> asyncHandler = originalAsyncHandler; |
98 | 101 | AdviceScope adviceScope = AdviceScope.start(request); |
99 | | - if (adviceScope == null) { |
100 | | - return new Object[] {null, asyncHandler}; |
| 102 | + if (adviceScope != null) { |
| 103 | + asyncHandler = adviceScope.wrap(asyncHandler); |
101 | 104 | } |
102 | | - return new Object[] {adviceScope, adviceScope.wrap(asyncHandler)}; |
| 105 | + return new Object[] {adviceScope, asyncHandler}; |
103 | 106 | } |
104 | 107 |
|
105 | 108 | @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) |
|
0 commit comments