0

There is a synchronized code block shown as below:

public class Counter {
  int count;  

  public void increment(){
    synchronized(this){
      this.count ++;   
    }   
  }
}

I know how to use bytebuddy to intercept the instrument method. Can bytebuddy intercept the synchronized code block as well?

My ultimate goal is to inject my own code in the beginning or the end of the code block.

1 Answers1

0

There is no API in Byte Buddy to change code within a method; all such operations are however possible by using ASM which is exposed by Byte Buddy by using a AsmClassVisitorWrapper that you can register in its API.

Rafael Winterhalter
  • 42,759
  • 13
  • 108
  • 192