byte-buddy icon indicating copy to clipboard operation
byte-buddy copied to clipboard

intercept jdk

Open shixiaoxianga opened this issue 3 years ago • 4 comments

Hello, author, I want to intercept classes in JDK. First, I need to inject the interceptor into the boot class loader. What can I do next? Can you give me some suggestions or provide some ideas.Thank you very much.It's best to have examples

shixiaoxianga avatar Jul 02 '22 13:07 shixiaoxianga

Can classes in JDK intercept construction methods?

shixiaoxianga avatar Jul 03 '22 03:07 shixiaoxianga

Yes, you can intercept constructors just as methods with minor limitations. By default, Byte Buddy ignores all JDK types. You need to define a custom ignore matcher on your agent builder. Note that this will impact performance and you should try to exclude as many JDK packages as possible.

raphw avatar Jul 05 '22 17:07 raphw

@raphw Should the classes referenced by the interceptor also be injected into the boot class loader?

shixiaoxianga avatar Jul 06 '22 08:07 shixiaoxianga

yes, all types referenced by the code that you want to run in the interceptor should be accessible and available for the boot class loader because of the JRE classloading strategy

yaohwu avatar Jul 06 '22 08:07 yaohwu