As Holger suggested, this is not within the scope of what Byte Buddy tries to achieve. Byte Buddy attempts offering a safe environment for code manipulations where in your case, it would need to validate that Bar
is a valid replacement for Foo
. Also, it would need to recompute stack map frames what is rather expensive.
If you want to use Byte Buddy, it offers access to ASM which is underlying. ASM offers Remapper
which you can use for such a thing. If you only want to do this, you should probably consider to use ASM without Byte Buddy. As Holger mentions in his comment, the most efficient way would be to rewrite the constant pool entry which is the root reference to Foo
which ASM does not support so you might even want to find another way, even though a simple ASM visitation does not generate too much overhead.