Intro Ex1 Ex2 Ex3

Tracing: Exposing the receiver

Task: Pass the suite tests.ReceiverTraceOutput.

Write a similar aspect to log the execution of all public methods in the figures package. This time, include the string representation of the receiver as well as the join point. The log lines should follow this pattern:

 thisJoinPointInfo at targetObject
Use the primitive pointcut target.

With your aspect you should be able to pass the tests of suite tests.ReceiverTraceOutput.

Do you receive StackOverflowErrors? This is a common pitfall in AspectJ (see the FAQ entry). An infinite loop occurs because inside of the control-flow of the advice body is a new matching join point, which causes a new invocation of the advice body, which causes a new join point and so on.

To discover the root of the infinite loop, consider the difference between this advice body and the one from the previous exercise. Another clue is in the “official” description of Java String Concatenation. Solve the problem by making the pointcut more restrictive: it should exclude join points in the control flow of the advice execution.


After you have completed the exercise, remove your aspect from the build path; then continue with Exercise 3.