java - Bytecode manipulation to intercept setting the value of a field -
using library asm
or cglib
, there way add bytecode instructions class execute code whenever value of class field set?
for example, let’s have class:
public class person { bool dirty; public string name; public date birthdate; public double salary; }
let’s section of code contains line:
person.name = "joe";
i want instruction intercepted dirty
flag set true
. know possible setter methods -- person.setname (“joe”)
-- class methods can modified bytecode manipulation, want same thing field.
is possible, , if so, how?
edit
i want avoid modifying code section accesses class, i'm looking way keep interception code part of person
class. there pseudo-methods field access, similar properties in python classes?
there 2 bytecodes updating fields: putfield
, putstatic
(see http://java.sun.com/docs/books/jvms/second_edition/html/instructions2.doc11.html). these found in code using class, there's no way modify person
.
Comments
Post a Comment