[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] bug in pointcut matching/cflow?

That is a dark corner isn't it, I would never recommend writing
something like that.

Anyway, with the extra clause '&& !(execution(* *.condition()))' you
are statically excluding the method-execution of condition().  Without
that we have to dynamically work out that it is excluded.  Currently
you hit the infinite loop before it can return 'no, this isn't a
match'.  This happens because when the pointcut is rewritten in a
normal form, the if() is considered cheaper than the cflow() and so
its runtime check is inserted first.  Because of this we recurse into
the if() over and over before just asking the cflow and determining it
isn't a match.

I've raised and fixed this under
https://bugs.eclipse.org/bugs/show_bug.cgi?id=315651

Andy

On 31 May 2010 09:24, Eric Tanter <etanter@xxxxxxxxxxxxx> wrote:
> Hi,
>
> From the semantics of AspectJ, it is given that cflow(pc()) *always* matches whenever pc() matches.
>
> While exploring some dark corners, we stumbled across a case where this is however _not_ the case.
>
> It has a strong feel of being a bug, but maybe not, so please let us know.
>
> The code below shows that the program with the scope() pointcut defined as:
> if(condition()) && !cflow(execution(* *.condition()));
>
> enters an infinite loop, while adding the condition
> && !(execution(* *.condition()))
>
> does not loop anymore (ie. works fine).
>
> So this is a case where
> !cflow(pc()) && !pc() is _not_ equivalent to !cflow(pc())
>
> (and according to the semantics, it should be:
> !cflow(pc()) && !pc()
> =
> !(cflow(pc()) || pc())
> where the || pc() part is clearly redundant
>
> Some additional notes:
> - this does not have anything to do, it seems, with the fact that lexical join points in if pcds are hidden (we are talking about execution pcds in the code, not calls)
> - moving the condition() method outside of the aspect does not change what we observe.
>
> Can you confirm if this is a bug, or are we missing something??
>
> Thanks,
>
> -- Éric
>
> package test;
> public aspect Profiling {
>        pointcut profile(): execution(* *.*(..)) ;
>
>        private pointcut scope() :
>                        if(condition())
>                        //&& !(execution(* *.condition())) <- uncomment and infinite loop disappears
>                        && !cflow(execution(* *.condition()));
>
>        public static boolean condition(){
>                return (Math.random()<2); //always true
>        }
>        before(): profile() && scope() {
>                System.out.println("Entering method "+thisJoinPointStaticPart.getSignature());
>        }
> }
>
> package test;
> public class Main {
>
>        private static int plus(int first, int second){
>                return first + second;
>        }
>        public static void main(String[] args) {
>                int num = plus(42,13);
>                System.out.println(num);
>        }
> }
>
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>