Implementing this spec. would be tricky. Because:
test.array = 10;
is compiled into:
long a = test.array; a = 10;
It would be difficult to recognize "a" is "test.array" when Javassist transforms "a = 10".
It seems this isn't the case for the sun compiler:
20: getfield #2; //Field array:[J
Or did you mean that a user can assign it to a local var and manipulate it there?
In that case, couldnt you store a reference map from local vars to arrays you are interested in?
I heard from Emmanuel that you'd discussed array interception with him and that it might be possible, but with some limitations.
Could you please explain the limitations a bit?
In particular Emmanuel mentioned differences between different compilers and reassignment of the array variables. As a first cut, I think it would be fine to not allow reassignment of variables, but the Hibernate and POJOCache guys will need to verify if this works for them.
I have implemented an Editor for the array fetch and store bytescodes.
There is one, possibly significant, limitation at present. For object arrays,
it does not know the type. The reason is that this is not trivially
apparent from the bytecodes (unlike calls, for example, where you a
signature, and fields give their declared type).
I have begun writing the code necessary to propagate type information
(similar to what is needed in a bytecode verifier, but limited just to this
purpose), but won't have the chance to finish it for a while.
Note that this just intercepts every usage at a particular code point.