Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] Guidaance on Cflow usage

Hi!

I'm having trouble coming to grasps with cflow pointcuts.  In the
example below, I was surprised to find out that cflow advice is included
in the set of cflow join points, which leads to an infinite recursion.
Although I'm tempted to submit this as a bug, I'm not wholly convinced I
understand what I'm doing.  Moreover, the bug submission system is down.

Any comments on the problem are more than welcome!

Cheers,


DL


WordCounterDemo.java

class WordCounterDemo 
{
  static String[] smallSample= {"This", "demos", "infinite", "loop",
"in", 
                                 "cflow", "before", "advice"};

  public static void main(String[] args) {
    WordCounter wordCounter = new WordCounter();
    String word;
    String[] wordList1 = smallSample;
    int words = 0;
    for (int i = 0; i < wordList1.length; i++) {
      word = smallSample[i];
      System.out.println("Adding " + word +", as word #" +  (++words));
      wordCounter.Add(word);
    }
  }
}

WordCounter.java

public class WordCounter {
  public void Add(String word) {
    System.out.println("Add entry, word = "+word.toString());
  }
}

Cflow.aj

public aspect Cflow {
  pointcut AddCflow():  cflow( execution( * WordCounter.Add( * )));

  // In AspectJ 1.0.6 and 1.1 here is an infinite loop here, because the

  // before advice is itself considered a join point in the cflow.
  before(): AddCflow() { System.out.println("Before advice call" ); }
}

CflowWeave.lst

WordCounterDemo.java
WordCounter.java
Cflow.aj


Which compiles with:

ajc -argfile CflowWeave.lst

And runs with:

java -classpatch "%CLASSPATH;./" WordCounterDemo

Gives the output

Adding This, as word#1
Exception in thread "main" java.langStackOverflowError





Back to the top