[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] Newbie Question: Aspect behaviour?

This is the second of my newbie questions about AspectJ. See "Newbie Questions: Biggest Issue" for the previous one....

My next question is about some odd behaviour I got when I added a second pointcut that would have involved the same method of my play program. (The previous email contains the full contents of the play program.)

When I had this as my aspect:

====================================================

package test;

public aspect LogCount {

    pointcut howManyNeedles() : execution(* Test01.count(..));

//    pointcut howManyNeedles2() : call(int count(String, String));

    /* First Before */
    before() : howManyNeedles() {
        System.out.println("About to count...."); //$NON-NLS-1$
    }

    /* First After */
    after() returning() : howManyNeedles() {
        System.out.println("...Needles counted");  //$NON-NLS-1$
    }

}



=====================================================

The "About to count...." and "...Needles counted" lines got printed once each as expected.

Then I changed the code by commenting out pointcut howManyNeedles() and creating a pointcut howManyNeedles2(). Then I changed all incidents of howManyNeedles() to howManyNeedles2() in the "before" and "after" so that the code looked like this::

=======================================================
package test;

public aspect LogCount {

//    pointcut howManyNeedles() : execution(* Test01.count(..));

    pointcut howManyNeedles2() : call(int count(String, String));

    /* First Before */
    before() : howManyNeedles2() {
        System.out.println("About to count...."); //$NON-NLS-1$
    }

    /* First After */
    after() returning() : howManyNeedles2() {
        System.out.println("...Needles counted");  //$NON-NLS-1$
    }

}
=======================================================

Much to my surprise, I got "About to count..." TWICE, followed by "...Needles counted", also twice.

Why did that happen? I would have thought I'd get those two lines once each since howManyNeedles() was now commented out but it still seemed to be in effect despite that.

Do I need to do something more involved like "de-registering" a pointcut from some kind of list kept by the system if I don't need it any more?

--
Rhino