Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

include method does not exist for Method Delegation approach #1640

Open
arorakshayy opened this issue May 13, 2024 · 6 comments
Open

include method does not exist for Method Delegation approach #1640

arorakshayy opened this issue May 13, 2024 · 6 comments
Assignees
Labels
Milestone

Comments

@arorakshayy
Copy link

arorakshayy commented May 13, 2024

I found this code online which tells bytebuddy where to search for the advice class:
agentBuilder.transform(
new AgentBuilder.Transformer.ForAdvice()
.include(
Utils.getBootstrapProxy(),
Utils.getAgentClassLoader(),
Utils.getExtensionsClassLoader())
.withExceptionHandler(ExceptionHandlers.defaultExceptionHandler())
.advice(methodMatcher, adviceClassName));

I verified and this works fine when working with advice.
In my case, I am using MehtodDelegation and want the same functionality (similar method like 'include'). I want to explicitly tell bytebuddy where to look for intercepted classes. But, I couldn't find similar thing in MethodDelegation.
Is there something that I am missing, or is there any other approach I can follow?
I want to bypass the default class loading hierarchy and want byte buddy to search for classes in my custom class loaders.

@raphw
Copy link
Owner

raphw commented May 13, 2024

MethodDelegation had different annotations. Are you sure that you placed the right one?

@raphw raphw self-assigned this May 13, 2024
@raphw raphw added the question label May 13, 2024
@raphw raphw added this to the 1.14.14 milestone May 13, 2024
@arorakshayy
Copy link
Author

MethodDelegation had different annotations. Are you sure that you placed the right one?

I tried multiple things. Nothing worked for me. My Delegated class is loaded by my custom loader and my agent could not load that when http call id made.
Can you tell me exactly what will work here for MethodDelegation?

@raphw
Copy link
Owner

raphw commented May 13, 2024

Well, there is two limitations:

  • The delegate class needs to be on the same class loader.
  • The annotations on the delegate method need to be from the bind package.

@arorakshayy
Copy link
Author

Well, there is two limitations:

  • The delegate class needs to be on the same class loader.

The delegate class needs to be on the same class loader.
Is there any way to bypass this. I am instrumenting java http classes (loaded by bootstrap class loader). And my instrumentation classes are loaded by my custom class loader.
Using Advice will have the overhead of causing issues at run time. Method delegation will prevent actual method implementation to conflict with my custom code.

@raphw
Copy link
Owner

raphw commented May 13, 2024

No, that is how the JVM works, unfortunately. Advice, by default, inlines the code, this is why this is not the case here.

@arorakshayy
Copy link
Author

Got it, one more thing
While using advice, can I tell advice to not call the original method and return some custom mocked response? Is that possible? Is it a good approach?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants