Bug 74913 - !cflowbelow(within(A)) causes ExceptionInitializerError
Summary: !cflowbelow(within(A)) causes ExceptionInitializerError
Status: RESOLVED INVALID
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 1.2.1   Edit
Assignee: Adrian Colyer CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-09-24 01:00 EDT by Adrian Powell CLA
Modified: 2004-10-21 04:30 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Adrian Powell CLA 2004-09-24 01:00:03 EDT
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"
Comment 1 Adrian Colyer CLA 2004-09-24 10:23:22 EDT
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.
Comment 2 Adrian Colyer CLA 2004-10-21 04:30:53 EDT
Fix released as part of AspectJ 1.2.1