[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [aspectj-users] pertarget anomaly (was: bug with pertarget?)

Hash: SHA1

David Pearce wrote:
> Hi all,
> Well, i'm still chasing up a few things regarding use of pertarget.
>  One thing I want to do is associate state with objects which are
> constructed and then monitor modifications to their fields.  The
> following gives an   
> example:
>> public aspect taspect pertarget(call(*.new(..)) &&
>> !within(taspect)) { 
>>     after(Object o) : target(o) && call(*.new(..)) &&
>> 	!within(taspect) { System.err.println("CONSTRUCTING - " + o);
>>     }
>>     after(Object o) : target(o) && set(* *.*) && !within(taspect)
>> { 	System.err.println("SETTING - " + o);
>>     }
>> }
>> public class test {
>>     public int testField;
>>     public static void main(String argv[]) {
>> 	test t = new test();
>> 	t.testField = 0;
>>     }
>> }
> However, this does not work - neither "CONSTRUCTING - ..." nor
> "SETTING - ..." messages are printed.  According to Ramnivas Laddad
> in his reply to my previous mail on this topic (see "re: bug with
> pertarget?"), the reason for this is:  
>> This is due to implicit limiting of join points when using any of
>> the per- associations. For pertarget() associations, the advice
>> application (or the scope of 
>> aspect) is limited to where the join point's target object matches
>> the 
>> aspect's associated object (target object at call(test.new(..))).

I am not sure, if I get it right, but I guess, the problem is that in
the current implementation, if you specify "pertarget", the target
object is passed to the instance field for inspection/exposure
immediately before the call (because immediately before the call the
target object of course cannot be altered any more). When using a
constructor, however, the object does not exist yet. So that's a
special case that *could* be handled but in fact is not here. I am
not sure, if ABC does (CC to them)... However I think this could and
should be handled in future releases. Maybe you or me should file a
feature request.


- -- 
Eric Bodden
Chair I2 for Programming Languages and Program Analysis
RWTH Aachen University

Version: PGP 8.0.3