Remove the useless resetClassFileTransformer in Enhancer (#1786)

This commit is contained in:
索悟 2021-04-30 14:48:38 +08:00 committed by GitHub
parent 843a3ed0aa
commit adf7725618
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -442,16 +442,8 @@ public class Enhancer implements ClassFileTransformer {
} }
} }
final ClassFileTransformer resetClassFileTransformer = new ClassFileTransformer() {
@Override
public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined,
ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException {
return null;
}
};
try { try {
enhance(inst, resetClassFileTransformer, enhanceClassSet); enhance(inst, enhanceClassSet);
logger.info("Success to reset classes: " + enhanceClassSet); logger.info("Success to reset classes: " + enhanceClassSet);
} finally { } finally {
for (Class<?> resetClass : enhanceClassSet) { for (Class<?> resetClass : enhanceClassSet) {
@ -464,18 +456,13 @@ public class Enhancer implements ClassFileTransformer {
} }
// 批量增强 // 批量增强
private static void enhance(Instrumentation inst, ClassFileTransformer transformer, Set<Class<?>> classes) private static void enhance(Instrumentation inst, Set<Class<?>> classes)
throws UnmodifiableClassException { throws UnmodifiableClassException {
try { int size = classes.size();
inst.addTransformer(transformer, true); Class<?>[] classArray = new Class<?>[size];
int size = classes.size(); arraycopy(classes.toArray(), 0, classArray, 0, size);
Class<?>[] classArray = new Class<?>[size]; if (classArray.length > 0) {
arraycopy(classes.toArray(), 0, classArray, 0, size); inst.retransformClasses(classArray);
if (classArray.length > 0) {
inst.retransformClasses(classArray);
}
} finally {
inst.removeTransformer(transformer);
} }
} }
} }