I am trying to use bytebuddy to intercept getfield
and putfield
accesses. I have read the rather comprehensive documentation on the site, but from what I can understand, it covers adding getters and setters to fields, rather than intercepting field accesses.
Here is basically what I am trying to do:
...
obj.prop = value;
x = obj.prop;
...
That in both these cases, I am trying to have some method called (or some bytecode inserted) before/after the field access. I was thinking of using Advice
to do it, but I am unable to find a way to have it for something other than methods.
Edit:
I am using a Java Agent to do it.
I had an idea of adding a dup
to duplicate the object reference followed by the call to a static method I defined to intercept the access (I only care about the object being referred to, not the field).