Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Pointcut - NoAspectBoundException

Normally the aspect state (for singleton aspects) is initialized very early - by code inserted into the static initializer for the aspect.  I probably need to see a more complete failing example to comment on what is happening to you. If I try to replicate what you describe, I don't see the NoAspectBound, so I must be doing something a little different to you.  Normally a NoAspectBound could indicate your aspect is advising itself and attempting to run advice before the static initializer has done its job. If you can post a failing sample I'll explain why it is doing what it is doing.

On your second point:
> For example the following point cut:
>
>    @Pointcut("call(* com.blah.profiler.aspects.HelloWorld(..))")
>    public void callPointCut() {
>    }
>
> Is called for non-static methods i've defined in HelloWorld.  How do I include static methods in the Pointcut definition?

As you haven't specified static or !static, that pointcut should be matching calls to static or non-static methods. If you wanted to limit it to static:

call(static * com.blah.profiler.aspects.HelloWorld(..))

If you wanted just non static

call(!static * com.blah.profiler.aspects.HelloWorld(..))

Hope that helps,

cheers,
Andy



On 21 November 2012 00:48, Brian Toal <brian.toal@xxxxxxxxx> wrote:
Found the issue to my problem.

The default constructor was calling a method of another class before the aspect was initialized, which caused the exception.

What is the approach to initialize aspect state without hitting this exception?



On Mon, Nov 19, 2012 at 8:38 PM, Brian Toal <brian.toal@xxxxxxxxx> wrote:
I'm trying to create a generic pointcut that allows me to have a Before/After hook into method calls.  The point cut I use is:

    @Pointcut("call(* *(..))")
    public void callPointCut() {
    }

However I'm getting the following error when running the test program:

Exception in thread "main" org.aspectj.lang.NoAspectBoundException: Exception while initializing com.blah.profiler.aspects.ProfilerAspects: org.aspectj.lang.NoAspectBoundException: com.blah.profiler.aspects.ProfilerAspects
    at com.blah.profiler.aspects.ProfilerAspects.aspectOf(ProfilerAspects.java:1)
    at com.blah.profiler.aspects.HelloWorld.main(HelloWorld.java:8)
Caused by: org.aspectj.lang.NoAspectBoundException: com.blah.profiler.aspects.ProfilerAspects
    at com.blah.profiler.aspects.ProfilerAspects.aspectOf(ProfilerAspects.java:1)
    at com.blah.profiler.aspects.ProfilerAspects.<init>(ProfilerAspects.java:13)
    at com.blah.profiler.aspects.ProfilerAspects.ajc$postClinit(ProfilerAspects.java:1)
    at com.blah.profiler.aspects.ProfilerAspects.<clinit>(ProfilerAspects.java:1)
    ... 1 more


I'm assuming the following method is causing the grief in HelloWorld.

public static void main(String[] argv)

When I use the fully qualified class name in the pointcut definition I don't get this error, however I don't understand why the problem above is a issue in that case as well.

For example the following point cut:

    @Pointcut("call(* com.blah.profiler.aspects.HelloWorld(..))")
    public void callPointCut() {
    }

Is called for non-static methods i've defined in HelloWorld.  How do I include static methods in the Pointcut definition?





_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users



Back to the top