Answer the question
In order to leave comments, you need to log in
How to intercept all write operations on an object using bytecode modification?
For example, there is a method with a body:
... obj;
obj.field0 = 10;
obj.setSomeotherfield(12);
obj.getSomeList().add(value)
is also a beeping operation, in general, all method calls can be replaced, and in onChanged check whether hashCode has changed .... Answer the question
In order to leave comments, you need to log in
Similar things are done with AspectJ
Here is an example of how to intercept the setters of all classes in the specified package demo-aspectj
class
package ua.evhen.aspectj.demo.domain;
public class BankAccount {
private String pan;
private String panSate;
private String exDate;
private String panName;
private long clientId;
// getters and setter
}
package ua.evhen.aspectj.demo.aspect;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
@Aspect
public class BankAccountAspect {
@Before("execution(void ua.evhen.aspectj.demo.domain.*.set*(..)) && args(val)")
public void setMethod(Object val, JoinPoint jp) {
System.out.printf("%s := '%s'%n ", jp.getSignature().toShortString(), val);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question