I am working through many classes and transforming them. There are some classes that I do not have enough information for when I first visit them, and as such I need to revisit them. Since I do not know at the time of the first pass if I need to revisit, I copy the complete class with the first pass of modifications.
What I want to know is if it is possible to revisit a method and overwrite the method in the ClassWriter
byte[] b...
ClassReader cr = new ClassReader(b);
ClassWriter cw = new ClassWriter(read,0);
ClassAdapter ca = new ClassAdapter(cw);//First pass
cr.accept(ca,0);
ClassAdapter ca2 = new ClassAdapter(cw);//Second Pass
cr.accept(ca2,0);
The result of this code will give me verification errors due to duplicate field&method declarations.
You would have to initialise a new ClassReader using the new bytecode read from cw.toByteArray(). From there, you would repeat the other steps (new ClassWriter, new ClassAdapter etc.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With