Parameterize Advice Methods
See original GitHub issueIn a nutshell, I want to change parameter values of several methods using the same @Advice.OnMethodEnter and @Advice.OnMethodExit advice methods.
Moreover, I want the advice methods to behave differently (change different parameters), depending on which method they instrument.
new AgentBuilder.Default()
.type(named("com.example.MyClass"))
.transform((builder, typeDescription, classLoader, module) ->
builder
.visit(Advice.to(MyAdvice.class).on(named("doSomething1").and(...)))
.visit(Advice.to(MyAdvice.class).on(named("doSomething2").and(...)))
);
Referring to the example, I want the @Advice.OnMethodEnter and @Advice.OnMethodExit method in MyAdvice to change different parameters for doSomething1() and doSomething2(), but by using the same logic. Therefore, I would need to parameterize MyAdvice.
Since the @Advice.OnMethodEnter and @Advice.OnMethodExit methods are static, are there any ByteBuddy-way solutions for parameterizing them?
Otherwise I would need to use a global state and do the same kind of matching again which I’ve already done with the ElementMatchers, which bould be cumbersome.
Unfortunately, the interception api is not an option for me, since I don’t want to change the class schema.
Thanks in advance!
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (4 by maintainers)

Top Related StackOverflow Question
Thanks for your blazing fast answers. I’m trying to wrap my head around on how to the custom annotation has to look like.
So basically I can achieve this:
With an annotation like that?
If I’m on the right track, I’ll try to figure it out and post an answer as soon as I got something working 😃
Please reopen the ticket if you have further questions.