[PRL] AspectJ "feature"

John Clements clements at brinckerhoff.org
Tue Apr 5 11:22:07 EDT 2005


It's rude of me to crow, but I noticed (and Jeff Palm confirmed) a 
bizarre "feature" of AspectJ that explains something about how they 
think.

Here's a simple "Counter" class.  Increment mutates x, and legalDx (if 
it were called) checks that dx is > 0.

public class Counter {
	int x;
	Counter(int x) {this.x = x;}
	
	void increment(int dx){this.x += dx;}
	boolean legalDx(int dx){return dx > 0;}}

Here's a tiny example of creating a counter and calling increment:

public class CounterTest extends TestCase {
	public void test(){
		Counter c = new Counter(14);
		c.increment(-4);}}

Here's an aspect that adds a check on the argument passed to increment:

public aspect CheckDx {		
	before(Counter c, int dx): target(c) && args(dx) && call(void 
increment(int)) {
		if (! c.legalDx(dx)) {
			System.out.println("Illegal value for x");
			return;}}}

So, if increment is called with negative dx (as it is above), you'll 
get output on stdout.

All fine, and works as expected.

QUIZ QUESTION: what happens if you make a mistake in the name of the 
method called inside the advice?  E.G:

...
		if (! c.legalwhoopsbadnameDx(dx)) {
...


What happens is...


nothing.  No compile error, runs fine.  The advice is _not_ applied, no 
output to stdout.  I can only guess that type information from the body 
(in this case, the existence of a 'legalwhoopsbadnameDx' method) is 
implicitly added to the pointcut,

Now imagine you're working on a 100KLoc program, and you change the 
name of a method.  You change all the uses of the method (using 
compiler error messages, say), until it compiles.  And runs!  
Unfortunately, your aspects no longer apply to the same join points 
that they used to.  Yikes!

Is this something that Gregor et. al. consider "the right thing?"


john
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2430 bytes
Desc: not available
Url : https://lists.ccs.neu.edu/pipermail/prl/attachments/20050405/0ff859a5/smime.bin


More information about the PRL mailing list