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

Can I replace the new byte[] in the onTransformation method?

Open 17396900506 opened this issue 2 years ago • 1 comments

I want to use jacoco's instrument() in the onTransformation() method to replace the new byte[] file. How can I let byte buddy load this replaced byte[] file?

@Override public void onTransformation(TypeDescription typeDescription, ClassLoader classLoader, JavaModule module, boolean loaded, DynamicType dynamicType) { System.out.println("onTransformation=" + typeDescription.getName() + ",classLoader=" + classLoader); byte[] bytes = dynamicType.getBytes(); try { byte[] instrument = new Instrumenter(new LoggerRuntime()).instrument(bytes, typeDescription.getName()); } catch (IOException e) { throw new RuntimeException(e); } dynamicType.inject(); }

17396900506 avatar Jan 24 '24 03:01 17396900506

Why would you need ByteBuddy for this? Simply register a ClassFileTransformer and return the byte array you want to replace.

raphw avatar Jan 24 '24 11:01 raphw