Last active
April 17, 2018 22:02
-
-
Save raphw/83e6c58a3380f5878e2103ab0a6f78aa to your computer and use it in GitHub Desktop.
Demonstrating loosing the deprecated modifier with retransformation when two transformers are registered using an old Log4j (Java 1.1).
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 org.objectweb.asm.ClassReader; | |
import org.objectweb.asm.util.TraceClassVisitor; | |
import java.io.PrintWriter; | |
import java.lang.instrument.ClassFileTransformer; | |
import java.lang.instrument.Instrumentation; | |
import java.security.ProtectionDomain; | |
public class BugReportDeprecatedModifier { | |
public static void main(Instrumentation inst) throws Exception { | |
ClassReader classReader = new ClassReader("org.apache.log4j.Category"); | |
classReader.accept(new TraceClassVisitor(new PrintWriter(System.out)), 0); | |
Class<?> type = Class.forName("org.apache.log4j.Category"); | |
inst.addTransformer(new ClassFileTransformer() { | |
@Override | |
public byte[] transform(ClassLoader loader, | |
String className, | |
Class<?> classBeingRedefined, | |
ProtectionDomain protectionDomain, | |
byte[] classfileBuffer) { | |
if ("org/apache/log4j/Category".equals(className)) { | |
ClassReader classReader = new ClassReader(classfileBuffer); | |
classReader.accept(new TraceClassVisitor(new PrintWriter(System.out)), 0); | |
} | |
return null; | |
} | |
}, true); | |
inst.retransformClasses(type); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment