I am trying to delete a method from a class file using Javassist.
Target class:"RemoveMethod"
.
Target method:"DoubleCheck"
.
My codes:
package javassist;
import java.io.IOException;
import java.lang.reflect.Method;
import javassist.*;
public class cRepair {
public static void main(String[] args) throws NotFoundException, IOException, CannotCompileException{
ClassPool pool = ClassPool.getDefault();
CtClass ctClass = pool.get("javassist.RemoveMethod");
CtMethod ctm = ctClass.getDeclaredMethod("DoubleCheck");
ctClass.removeMethod(ctm);
ctClass.writeFile("C:/Users/workspace/Javaproject1/src/javassis");
}
}
Then,run the code using the file "javassist.jar":
javac -cp javassist.jar cRepair.java
Then check the target class:
javap -verbose RemoveMethod.class
The method "DoubleCheck" is still there!
This looks really odd. Why could this happen and how to fix it?