Bug 71793 - NoAspectBoundException when initializing fields in aspect constructor
Summary: NoAspectBoundException when initializing fields in aspect constructor
Status: REOPENED
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P5 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Adrian Colyer CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-08-11 11:24 EDT by Eric Bodden CLA
Modified: 2009-08-30 02:48 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 Eric Bodden CLA 2004-08-11 11:24:37 EDT
This code...

public aspect Test {
	
	int field;
	
	public Test() {
		field = 0;
	}

..some pieces of advice...

}

...leads to this exception:

org.aspectj.lang.NoAspectBoundException: Exception while initializing aha_Test: 
org.aspectj.lang.NoAspectBoundException: aha_Test
	at aha.Test.aspectOf(Test.aj)
	at aha.Aha.main(Aha.java)
Caused by: org.aspectj.lang.NoAspectBoundException: aha_Test
	at aha.Test.aspectOf(Test.aj)
	at aha.Test.<init>(Test.aj:21)
	at aha.Test.ajc$postClinit(Test.aj)
	at aha.Test.<clinit>(Test.aj:16)
	... 1 more
Exception in thread "main" 


I assume that something weird happens when I set field in initialization phase!?
Comment 1 Adrian Colyer CLA 2004-08-11 11:42:42 EDT
whether or not this is a bug depends on exactly what the "some pieces of advice" 
are. If you are trying to advise a join point that happens before the aspect is 
constructed (like any field set in the aspect perhaps?) then the behaviour you 
are seeing is correct. Please confirm or supply a complete test case that 
reproduces the bug...

Thanks, A.
Comment 2 Eric Bodden CLA 2004-08-11 11:46:27 EDT
Yes, I am having a set-advice on that field. That makes sense, cheers.
However, I would wish to have a better error message in that case if possible. 
(e.g. output, what advice causes this error)
Comment 3 Adrian Colyer CLA 2004-08-18 09:11:02 EDT
I'm moving this to an enhancement request. The exception you see occurs at 
runtime (obviously) and gives pretty good information already: whilst 
initializing the "aha_Test" aspect ("aha.Test" would have been better there), an 
attempt was made to obtain the aha.Test aspect instance, and a 
NoAspectBoundException was thrown".

The enhancement to be considered is that is some cases we know statically that 
this problem is going to occur - i.e. when weaving advice into an aspect 
initializer, and that advice has no runtime test associated with it. In such 
circumstances we could put out a compilation error. Your program would be one 
such situation I suspect.
Comment 4 Adrian Colyer CLA 2005-08-26 11:08:45 EDT
We're not going to get to this in AJ 1.5.0. Marking as "LATER" for consideration
in 1.5.1 and future release planning.
Comment 5 Eclipse Webmaster CLA 2009-08-30 02:48:47 EDT
LATER/REMIND bugs are being automatically reopened as P5 because the LATER and REMIND resolutions are deprecated.