[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] Using cflowbelow to detect cycles in the call graph - Not working

Hi, I'm trying out the following simple example whereby I have two classes, which contain an object of the other class's type in each. I then proceed to construct four objects in such a way that a cycle is created. When I call the equals method, I should get an infinite cycle. I tried to create a pointcut descriptor that detects this. Unfortunately, this only works when the nesting level in the call stack is less than 4. I need to create a PCD which detects cycles when the same equals method in the same object is called in the same call stack. Here is the code (which doesn't work as it should):

import java.util.*;

class Launcher {
ÂÂÂ public static void main(String[] args) {
ÂÂÂÂÂÂÂ Test1 t1=new Test1(1);
ÂÂÂÂÂÂÂ Test2 t2=new Test2(2);
ÂÂÂÂÂÂÂ Test1 t3=new Test1(3);
ÂÂÂÂÂÂÂ Test2 t4=new Test2(4);
ÂÂÂÂÂÂÂ t1.myObject=t2;
ÂÂÂÂÂÂÂ t2.myObject=t3;
ÂÂÂÂÂÂÂ t3.myObject=t4;
ÂÂÂÂÂÂÂ t4.myObject=t1;
ÂÂÂÂÂÂÂ assert t3.equals(t1);
ÂÂÂÂÂÂÂ System.out.println("haha, no more cycles!");
ÂÂÂ }
}
class Test1 {
ÂÂÂ public Test1(int c) { i=c; }
ÂÂÂ int i;
ÂÂÂ Test2 myObject;
ÂÂÂ public boolean equals(Object o) {
ÂÂÂÂÂÂÂ System.out.println(i);
ÂÂÂÂÂÂÂ return myObject.equals(((Test1)o).myObject);
ÂÂÂ }
}

class Test2 {
ÂÂÂ public Test2(int c) { i=c; }
ÂÂÂ int i;
ÂÂÂ Test1 myObject;
ÂÂÂ
ÂÂÂ public boolean equals(Object o) {
ÂÂÂÂÂÂÂ System.out.println(i);
ÂÂÂÂÂÂÂ return myObject.equals(((Test2)o).myObject);
ÂÂÂ }
}

aspect A {
ÂÂÂ pointcut inTest1(Test1 i): call(boolean Test1.equals(Object)) && target(i);
ÂÂÂ pointcut inTest2(Test2 i): call(boolean Test2.equals(Object)) && target(i);

ÂÂÂ boolean around(Test1 up, Test1 now):
ÂÂÂÂÂÂÂ inTest1(now) && cflowbelow(inTest1(up)) && if(up==now){
ÂÂÂÂÂÂÂ return true;
ÂÂÂ }
ÂÂÂ boolean around(Test2 up, Test2 now):
ÂÂÂÂÂÂÂ if(up==now) && cflowbelow(inTest2(up)) && inTest2(now) {
ÂÂÂÂÂÂÂ return true;
ÂÂÂ }

}


--
Regards,
Neville Grech