Byte Buddy offers different Instrumentation
implementations which are all composed by the mentioned StackManipulation
s. However, no prebuilt instrumentation requires an ASTORE
instruction which is why it is not predefned. You can however easily implement your own implementation for this purpose:
class AStrore implements StackManipulation {
private final int index; // Constructor omitted
public boolean isValid() {
return index >= 0;
}
public Size apply(MethodVisitor methodVisitor, Instrumentation.Context context) {
methodVisitor.visitIntInsn(Opcodes.ASTORE, index);
return new Size(-1, 0);
}
}
Note however that you then make direct use of ASM which suffers compatbility issues. For this reason, please read the information on Byte Buddy's website of how to repackage ASM and Byte Buddy into your own namespace.
Also note that you could avoid the ASTORE
instruction by directly casting the instance before the call.