Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] Advice ordering and circular dependencies

                                   Hi!

  I am not sure whether this is a bug in the compiler or just something I do 
not yet understand about ordering the advice within an aspect.

  Try this:

<-- clip -->

public class Foo {

  public static void main(String[] args) {
    Foo f = new Foo();
    f.aMethod();
  }

  void aMethod() {
    System.out.println("Hello");
  }

}

aspect SampleAspect {

  pointcut myCut(): call(* Foo.*());


  after(): myCut() {
      System.out.println("<<< " + thisJoinPointStaticPart);
  }

  before(): myCut() {
      System.out.println("<<< " + thisJoinPointStaticPart);
  }

  void around(): myCut() {
    System.out.println("---Give the join point " +
               thisJoinPointStaticPart + " permission to proceed");
    proceed();
    System.out.println("---Join point " +
               thisJoinPointStaticPart + " done");
   }

}

</-- clip -->

  This compiles and runs fine. The order of the printed messages is logical 
given that the ordering of the advice within the aspect affects their 
precedence.

  Now change the order of the before and after advice:

<-- clip -->

aspect SampleAspect {

  pointcut myCut(): call(* Foo.*());

  before(): myCut() {
      System.out.println("<<< " + thisJoinPointStaticPart);
  }

  after(): myCut() {
      System.out.println("<<< " + thisJoinPointStaticPart);
  }

  void around(): myCut() {
    System.out.println("---Give the join point " +
               thisJoinPointStaticPart + " permission to proceed");
    proceed();
    System.out.println("---Join point " +
               thisJoinPointStaticPart + " done");
   }

}

</-- clip -->

  Trying to compile this does not succeed:

> ajc Foo.java 
/home/akaranta/temp/aspekti/advicesample/Foo.java:22 circular dependency at 
method-call(void Foo.aMethod())
/home/akaranta/temp/aspekti/advicesample/Foo.java:26 circular dependency at 
method-call(void Foo.aMethod())
/home/akaranta/temp/aspekti/advicesample/Foo.java:18 circular dependency at 
method-call(void Foo.aMethod())

3 errors

  So, is this a bug or is the compiler supposed to act this way? I would think 
that the order of the before and after advice in this case should have no 
effect...

  Some version info if it is needed:

> ajc -version
AspectJ Compiler 1.1.1

> uname -a
Linux hyperion 2.4.18-4GB #1 Wed Mar 27 13:57:05 UTC 2002 i686 unknown


-- 
Antti Karanta <Antti.Karanta@xxxxxxxxxxxxxx>
Konsultti
FCS Partners Oyj
ph +358407634648
http://www.fcspartners.fi



Back to the top