Reputation: 3152
When intercepting a method's implementation with an @Advice
, is it possible to access local variables?
Upvotes: 5
Views: 455
Reputation: 44077
No, it is not and this is partly by design. A method's implementation is supposed to be a private detail whereas advice adds code after and before an invocation where the method's signature is part of its API.
At some point, Byte Buddy might offer a possibility to replace certain field and method accesses but in a way that you do not rely on an implementation.
In order to mingle with the explicit byte code, Byte Buddy offers AsmVisitorWrapper
to use the ASM API directly which is better suited for byte code-level manipulation than Byte Buddy's high-level API.
Upvotes: 3