Skip to content

Instantly share code, notes, and snippets.

@raphw
Last active April 17, 2018 22:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raphw/83e6c58a3380f5878e2103ab0a6f78aa to your computer and use it in GitHub Desktop.
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).
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