Community
Participate
Working Groups
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!?
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.
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)
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.
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.
LATER/REMIND bugs are being automatically reopened as P5 because the LATER and REMIND resolutions are deprecated.