Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Sample code from the programmer guide causes infinite loop (StackOverflowError)

Are you sure that is recommended code from the guide, and not some example of what not to do? Because of course that casuses a stack overflow...

Your pointcut

pointcut printPC() : call(void
 java.io.PrintStream.println(String));

matches every call of printstreams println. So whenever it is called, this pointcut is matched.

Your advice is to call println every time your pointcut is matched. So then you are going to match on that println, and call println again, and on and on for infinity..... You have the inifinite loop problem described in pitfalls/infinite loops. The proper way of avoiding the match of a method within your advice would be to do something like this:

before(): call(* *(..)) && !within(A) { System.out.println("before"); }
Where you are making sure you are not matching a method called within this aspect.

- Nathan




From: Peer Haja <peerhaja@xxxxxxxxx>
Reply-To: aspectj-users@xxxxxxxxxxx
To: aspectj-users@xxxxxxxxxxx
Subject: [aspectj-users] Sample code from the programmer guide causes infinite loop (StackOverflowError)
Date: Fri, 7 Mar 2003 06:49:09 -0800 (PST)

I have AspectJ installed. Running "ajc -version"
 gives:
   ajc version 1.0.6 (built Jul 24, 2002 6:21 PM PST)
 running on java 1.4.1-rc


The following code taken from the online programmer
 guide (Chapter 2) cause the StackOverflowError:

 public class Test {
   public static void main(String[] args) {
  	foo();
  }

  static void foo() {
 	goo();
  }

  static void goo() {
 	System.out.println("hi");
  }
 }

 aspect A {
 	pointcut fooPC() : execution(void Test.foo());
 	pointcut gooPC() : execution(void Test.goo());
 	pointcut printPC() : call(void
 java.io.PrintStream.println(String));

 	before() : printPC() {
 		System.out.println("Should occur");
 	}
 }

__________________________________________________
Do you Yahoo!?
Yahoo! Tax Center - forms, calculators, tips, more
http://taxes.yahoo.com/
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/aspectj-users


_________________________________________________________________
Help STOP SPAM with the new MSN 8 and get 2 months FREE* http://join.msn.com/?page=features/junkmail



Back to the top