开发者

printLn and reflection

开发者 https://www.devze.com 2023-04-12 17:05 出处:网络
I created a simple class (1)public class Inspector implements ClassFileTransformer{ (2)public byte[] transform(ClassLoader loader,

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号