Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] "cflow ( x()) && !cflowbelow( x()) " confuses me

Hi,

I have a quick question on cflow/cflowbelow that is wrecking my brain
and that I cannot find an example of in the mailing list.

Let me start with the example:

public class WordCounterDemo 
{
  public static void main(String[] args) 
  {
    WordCounter wordCounter = new WordCounter();
    System.out.println("*** About to call Find ***");
    int theCount = wordCounter.Find("the");
    System.out.println("*** Done calling Find  ***");
  }
}

public class WordCounter 
{
  public int Find(String word)  {
    String newWord = word.toLowerCase();
    return 0;
  }
}

public aspect Cflow {
  pointcut FindExec():   execution( int WordCounter.Find( String ));
  pointcut FindCflow():  cflow(FindExec()) && !cflowbelow( FindExec() );

  before(): FindCflow() 
  {
    System.out.println("Before joinpoint in FindCflow pointcut, sig " +
    thisJoinPointStaticPart.toLongString());
  }
}


And execution results in the following: 

*** About to call Find ***
Exception in thread "main" java.lang.StackOverflowError


The infinite loop can be removed by modifying the FindCflow() pointcut
to remove join points encountered in the cflow of adviceexecution, as
follows: 

pointcut FindCflow():  cflow(FindExec()) && !cflowbelow( FindExec() )
                       && !cflow(adviceexecution());


If we consider that the only difference between cflow and cflowbelow is
whether or not the join points that match explicitly the PCD's argument
are included in the set of join points selected by that PCD, then
wouldn't the only join points that match "cflow(FindExec()) &&
!cflowbelow(FindExec())" be those identified in FindExec()?  And yet,
join points other than those selected by FindExec() are being executed,
as evidenced by the infinite loop.

What is the bad assumption that I'm making?


DL


________________________________________________________
Donal Lafferty, P.Eng., BSc. Computer Engineering 
<http://www.dsg.cs.tcd.ie/~laffertd/>

"Statistically, 100% of the shots you don't take, don't go in." -Wayne
Gretzky




Back to the top