RE: transformation bug

"Jonas Bonèr" <[email protected]> Mon, 12 May 2003 16:40:19 +0200
Newsgroups gmane.comp.java.aspectwerkz
Message-ID <[email protected]>
Hi jianxiong.

Thanks a lot for catching the bug, even though it has already been fixed :-=
)

I tried your example using the new 0.5 release of AspectWerkz (donwloadable=
 from [http://aspectwerkz.codehaus.org/releases.html])

and it produces the following output:

----discard advice happened here -----
----send advice happened here -----
The discard method is runing
----send advice happened here -----
----discard advice happened here -----
The send method is running

which is correct.

> The result should be
>=20
> ----discard advice happened here -----
> The send method is running
> ----send advice happened here -----
> discard method is running
>=20

It can't produce this result since you are invoking simple.discard() in the=
 SendAdvice.execute(..) and simple.send() in the DiscardAdvice.execute(..=
) so the two methods will get called 4 times in total.

(I don't know what your intentions are but if you want to proceed with the =
normal method call you should call joinPoint.proceed()
But I guess you want it like this.)

So please go ahead and download the 0.5 release and help me catch all nasty=
 bugs there (if there are any... ;-))

Thanks.

- Jonas

Ps. This list should already have been closed, so please send further quest=
ions to the [email protected] list. Ds.


jianxiong pang wrote:
> Hi Honas,
>=20
> I like aspectwerkz!
>=20
> I think there is a bug in the transformation process. I write a simple
> program to repeat the problem.
> The problem is that an advice on a method in a class sometimes prevent
> another advice on another method at the same class from being advised.
> Please look the code below:
>=20
> without aspects.
> the output should be:
>=20
> The discard method is runing
> The send method is running
>=20
> with aspect. The result should be
>=20
> ----discard advice happened here -----
> The send method is running
> ----send advice happened here -----
> discard method is running
>=20
>=20
> but the result is now:
>=20
> The discard method is runing
> ----send advice happened here -----
> The discard method is runing
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D
> public class SendAdvice extends MethodAdvice {
>       public SendAdvice() {
>         super();
>       }
>     public Object execute(final JoinPoint joinPoint) throws Throwable {
>          MethodJoinPoint jp =3D (MethodJoinPoint)joinPoint;
>          SimpleState simple =3D (SimpleState)jp.getTargetObject();
>          Object result =3D null;
>         System.out.println("----send advice happened here -----");
>         simple.discard();
>         return result;
>    }
> }
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> public class DiscardAdvice extends MethodAdvice {
>       public DiscardAdvice() {
>         super();
>       }
>     public Object execute(final JoinPoint joinPoint) throws Throwable {
>          MethodJoinPoint jp =3D (MethodJoinPoint)joinPoint;
>          SimpleState simple =3D (SimpleState)jp.getTargetObject();
>          Object result =3D null;
>          System.out.println("----discard advice happened here -----");
>          simple.send();
>          return result;
>    }
> }
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> public class Main {
>=20
>      public static void main(String[] args) {
>             SimpleState simple =3D new SimpleState();
>             simple.feature(false);
>             simple.feature(true);
>      }
> }
> public class SimpleState {
>=20
>      public void send() { //Typically, hand to MailHost.
>        System.out.println("The send method is running");
>       }
>     public void feature(boolean runSend) {
>          if(runSend)
>             send();
>          else
>             discard();
>     }
>    public void discard() {
>      System.out.println("The discard method is runing");
>    }
> }
>=20
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> <aspectwerkz>
>=20
>  <advice name=3D"onDiscard"
>    advice=3D"samples/examples/aspects/on_discard/DiscardAdvice"
>        deploymentModel=3D"perJVM"/>
>  <advice name=3D"onSend"
>    advice=3D"samples/examples/aspects/on_send/SendAdvice"
>        deploymentModel=3D"perJVM"/>
> 
>  <aspect class=3D"samples.examples.core.bugshow.SimpleState">
>   <pointcut type=3D"method" pattern=3D"discard">
>    <advice-ref name=3D"onDiscard"/>
>   </pointcut>
>  </aspect>
>  <aspect class=3D"samples.examples.core.bugshow.SimpleState">
>   <pointcut type=3D"method" pattern=3D"send">
>    <advice-ref name=3D"onSend"/>
>   </pointcut>
>  </aspect>
> 
> </aspectwerkz>
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> 
> Cheers!
> 
> Jianxiong
> 
> 
> 


-- 
Jonas
http://freeroller.net/page/jboner



- Jonas



-------------------------------------------------------
Enterprise Linux Forum Conference & Expo, June 4-6, 2003, Santa Clara
The only event dedicated to issues related to Linux enterprise solutions
www.enterpriselinuxforum.com