Closed SaiprasadKrishnamurthy closed 6 days ago
By .load(ClassLoader.getSystemClassLoader(), ClassLoadingStrategy.Default.CHILD_FIRST)
you create a new class in a child loader. Once your regular program loads the class, it won't pick it up from that loader but load the original class. You would need to use an injection strategy, or use a MethodHandle.Lookup
to inject the class in the loader. To do so, you need to avoid loading the class:
DynamicType.Unloaded<BodyNode> unloaded = new ByteBuddy()
.redefine("your.packagelocation.BodyNode", ClassFileLocator.ForClassLoader.ofSystemLoader())
.visit(Advice.to(MyAdvices.class).on(ElementMatchers.isMethod()))
.make();
Class<? extends BodyNode> loaded = unloaded
.load(ClassLoader.getSystemClassLoader(), ClassLoadingStrategy.Default.INJECT) // or lookup when using Java 9+
.getLoaded();
Newbie Alert!
This is my main application.
My advice looks like this:
My 3rd party library when it calls BodyNode.render(...) with a hard coded object within it's class (using new), my advice isn't getting called. What am I missing? I'm looking to log a few things and then pass the control back to the original method (similar to the around advice).