I created a simple class
(1) public class Inspector implements ClassFileTransformer{
(2) public byte[] transform(ClassLoader loader,
String className, Class<?> clazz,
(3) ProtectionDomain domain, byte[] bytes)
(4) throws IllegalClassFormatException {
(5) // clazz.getName();
(6) System.out.println("in Transform");
(7) return bytes;
}
public static void premain(String agentArgument,
Instrumentation instrumentation) {
System.out.println("in premain");
instrumentation.addTransformer(new Inspector());
}开发者_运维百科
Output: in premain \n in Transform
Then if I uncomment the line number (5), I can't get all my println
after this line:
Output: in premain \n
and it is the same when I use every methods from the class Class...
Any idea?
I think it might be because clazz is null. It is only provided for class redefine or retransform. Your transform() method probably throws a NPE, which has the same effect as returning null, meaning no transformation is performed.
精彩评论