Skip to content

Parameterize Advice Methods #551

@AndreasMili

Description

@AndreasMili

In 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!

Metadata

Metadata

Assignees

Labels

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions