Community
Participate
Working Groups
Aspectj Compiler 1.1beta4 In the "Aspect Instantiation and Advice" section in README-11.html, it is said that an org.aspectj.lang.NoAspectBoundException will be thrown if a before advice captures all constructors executions (including the aspect constructor). aspect Watchcall { pointcut myConstructor(): execution(new(..)); before(): myConstructor() { System.err.println("Entering Constructor"); } } But adding a similar after advice to the same aspect will throw an obscure NoClassDefError instead, which gives no clues about what the error is.
The modified aspect: aspect Watchcall { pointcut myConstructor(): execution(new(..)); before(): myConstructor() { System.err.println("Entering Constructor"); } after(): myConstructor() { System.err.println("Leaving Constructor"); } } The Java class (unchanged): public class Client { public static void main(String[] args) { Client c = new Client(); } } The error stack trace: Exception in thread "main" java.lang.NoClassDefFoundError at Client.<init>(Client.java:1) at Client.main(Client.java:4)
This behavior was easily verified. Thanks for the simple test case. I'm unsure what the correct resolution is. The problem is a standard one with after advice. Because after advice will run even in the presence of exceptions, it can lead to confusing behavior in the same way that try/finally can. See the FAQ entry on "When I run, I get a StackOverflowError (or a long stack trace or no output whatsoever)" for more information on a different manifestation of this same issue. My recommendation in the short-term is to use after returning advice instead of after advice whenever possible to avoid these confusions. For the longer term this might merit discusion on the aspectj-dev list.
*** Bug 37256 has been marked as a duplicate of this bug. ***
Finally fixed! All exceptions that occur during the static intialization of a persingleton aspect will be swallowed. When using that aspect (via aspectOf()) a NoAspectBoundException will be thrown with the original exception from the staitc initializer as the cause.