Community
Participate
Working Groups
The following cflowbelow() pointcut causes an ExceptionInitializerError and dialog box to appear, title "Java Virtual Machine Launcher", body "Could not find the main class. Program will exit". Eclipse 3.0, ajdt 1.1.12 (AspectJ 1.2.0 I think). --- package test; public class SomeClass { public static void main(String[] args) { } } -- package test; public aspect TraceClass { pointcut pc() : !cflowbelow(within(TraceClass)); before () : pc() { System.out.println("-> " + thisJoinPointStaticPart); } } --- Output: java.lang.ExceptionInInitializerError at test.SomeClass.<clinit>(SomeClass.java) Caused by: org.aspectj.lang.NoAspectBoundException: test_TraceClass at test.TraceClass.aspectOf(TraceClass.aj) at test.TraceClass.<clinit>(TraceClass.aj) ... 1 more Exception in thread "main"
Strange as it may seem, this program is working as designed! Here's what's going on: * You have pointcut that matches EVERY join point that is NOT in the control flow below a join point in TraceClass. * One join point matched by this pointcut is the staticinitialization join point for SomeClass (the very first join point in the program execution). * In order to put into effect the before advice at this join point, the aspect TraceClass needs to be called. * This causes the TraceClass aspect to be loaded, giving rise to a staticinitialization join point. * The staticinitialization join point for TraceClass itself is also matched by the pointcut - so you have an aspect trying to advise its own initialization. * This is the situation that leads to the "NoAspectBoundException" (there is no instance of the aspect bound at the point at which the advice should execute). * Since the NoAspectBoundException is thrown during initialization of the SomeClass class, you get the "ExceptionInInitializer" error. The short summary is that an aspect can't advise its own static initialization.
Fix released as part of AspectJ 1.2.1