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 {
enhance(inst, resetClassFileTransformer, enhanceClassSet);
enhance(inst, enhanceClassSet);
logger.info("Success to reset classes: " + enhanceClassSet);
} finally {
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 {
try {
inst.addTransformer(transformer, true);
int size = classes.size();
Class<?>[] classArray = new Class<?>[size];
arraycopy(classes.toArray(), 0, classArray, 0, size);
if (classArray.length > 0) {
inst.retransformClasses(classArray);
}
} finally {
inst.removeTransformer(transformer);
int size = classes.size();
Class<?>[] classArray = new Class<?>[size];
arraycopy(classes.toArray(), 0, classArray, 0, size);
if (classArray.length > 0) {
inst.retransformClasses(classArray);
}
}
}