Created
June 13, 2014 08:03
-
-
Save trask/bee81e153cf17e1e945a to your computer and use it in GitHub Desktop.
ClassFileTransformer.transform() can be passed null className
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.lang.instrument.Instrumentation; | |
public class Agent { | |
public static void premain(String agentArgs, Instrumentation instrumentation) { | |
instrumentation.addTransformer(new Transformer()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.lang.invoke.MethodHandle; | |
import java.lang.invoke.MethodHandles; | |
import java.lang.invoke.MethodType; | |
public class Main { | |
public static void main(String... args) throws Exception { | |
MethodType mt = MethodType.methodType(String.class); | |
MethodHandle mh = MethodHandles.lookup().findVirtual(Object.class, "toString", mt); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Premain-Class: Agent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
className is null | |
className is null | |
className is null | |
className is null | |
className is null | |
className is null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
javac Agent.java Transformer.java Main.java | |
jar cmf MANIFEST.MF agent.jar Agent.class Transformer.class Main.class | |
java -javaagent:agent.jar Main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.lang.instrument.ClassFileTransformer; | |
import java.lang.instrument.IllegalClassFormatException; | |
import java.security.ProtectionDomain; | |
public class Transformer implements ClassFileTransformer { | |
@Override | |
public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, | |
ProtectionDomain protectionDomain, byte[] classfileBuffer) | |
throws IllegalClassFormatException { | |
if (className == null) { | |
System.out.println("className is null"); | |
} | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment