Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Oddity with @Around and proceed arguments

Hi Matthew!

I  haven't yet explored runtime weaving yet.  At the moment I'm using
1.5.0 and doing static weaving. I was running ajc via a script which
looks like this:

#! /bin/sh
build=.

ajc -1.5\
    -cp $build:/files0/AOP/AspectJ/aspectj1.5/lib/aspectjrt.jar \
    -verbose \
    -showWeaveInfo \
    -referenceInfo \
    -d . -argfile files.lst

with a list file containing:
A.java
C.java
M.java

and getting the following exception when run:
Exception in thread "main" java.lang.ClassCastException: java.lang.Integer
        at ron.interfacetest.M.bar_aroundBody1$advice(M.java:119)
        at ron.interfacetest.M.main(M.java:10)

A javap -c -private ron.interfacetest.M  shows where for some reason
there seems to be expected a push of two arguments, not one, and on the
first there is a checkcast (on type C):

   0:   aload   4
   2:   iconst_1
   3:   anewarray       #4; //class java/lang/Object
   6:   dup
   7:   iconst_0
   8:   iload   5
   10:  invokestatic    #53; //Method
java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
   13:  aastore
   14:  astore  6
   16:  astore  7
   18:  aload   6
   20:  bipush  0
   22:  aaload
   23:  checkcast       #18; //class ron/interfacetest/C
   26:  aload   6
   28:  bipush  1
   30:  aaload
   31:  invokestatic    #73; //Method
org/aspectj/runtime/internal/Conversions.intValue:(Ljava/lang/Object;)I
   34:  aload   7
   36:  invokestatic    #75; //Method
bar_aroundBody0:(Lron/interfacetest/C;ILorg/aspectj/lang/JoinPoint;)V
   39:  aconst_null
   40:  pop
   41:  return

When I add in the pjp.getTarget() back I get the following which
executes properly:

   0:   aload   4
   2:   iconst_2
   3:   anewarray       #4; //class java/lang/Object
   6:   dup
   7:   iconst_0
   8:   aload   4
   10:  invokeinterface #53,  1; //InterfaceMethod
org/aspectj/lang/ProceedingJoinPoint.getTarget:()Ljava/lang/Object;
   15:  aastore
   16:  dup
   17:  iconst_1
   18:  iload   5
   20:  invokestatic    #59; //Method
java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
   23:  aastore
   24:  astore  6
   26:  astore  7
   28:  aload   6
   30:  bipush  0
   32:  aaload
   33:  checkcast       #18; //class ron/interfacetest/C
   36:  aload   6
   38:  bipush  1
   40:  aaload
   41:  invokestatic    #77; //Method
org/aspectj/runtime/internal/Conversions.intValue:(Ljava/lang/Object;)I
   44:  aload   7
   46:  invokestatic    #79; //Method
bar_aroundBody0:(Lron/interfacetest/C;ILorg/aspectj/lang/JoinPoint;)V
   49:  aconst_null
   50:  pop
   51:  return

Hopefully this is helpful. 

=Ron=


Matthew Webster wrote On 01/26/06 10:06,:

>
> Ron,
>
> How are you building and running the application? Which version of
> AspectJ are you using? It works for me using a hand-coded aop.xml file
> and load-time weaving support. I had to change the aspect a little to
> cope with the fact that the "proceed()" method throws Throwable but
> this is what I got:
>
> _Console_
> 84
> info AspectJ Weaver Version DEVELOPMENT built on Friday Jan 20, 2006
> at 10:29:42 GMT
> info register classloader
> org.aspectj.weaver.loadtime.WeavingURLClassLoader
> info using /C:/workspaces/temp/Test/bin/META-INF/aop.xml
> info register aspect A
> info weaving 'M'
> info generating class 'M$AjcClosure1'
> info weaving 'C'
> info weaving 'A'
>
> _A.java_
> import org.aspectj.lang.ProceedingJoinPoint;
> import org.aspectj.lang.annotation.Around;
> import org.aspectj.lang.annotation.Aspect;
> import org.aspectj.lang.annotation.Pointcut;
>
> @Aspect
> public class A {
>
>     @Pointcut( "call(void C.bar( int )) && args( i ) " )
>     void fooOfC( int i ) {}
>
>     @Around("fooOfC( i )")
>     public void foo2( ProceedingJoinPoint pjp, int i) throws Throwable {
> //            pjp.proceed( new Object[] { pjp.getTarget(), i } );
>         pjp.proceed( new Object[] { i*2 } );
>     }
> }
>
> _aop.xml_
> <?xml version="1.0" encoding="UTF-8"?>
> <aspectj>
>         <aspects>
>                 <aspect name="A"/>
>         </aspects>
>         <weaver options="-verbose"/>
> </aspectj>
>
> Cheers
>
> Matthew Webster
> AOSD Project
> Java Technology Centre, MP146
> IBM Hursley Park, Winchester,  SO21 2JN, England
> Telephone: +44 196 2816139 (external) 246139 (internal)
> Email: Matthew Webster/UK/IBM @ IBMGB, matthew_webster@xxxxxxxxxx
> http://w3.hursley.ibm.com/~websterm/
>
> Please respond to aspectj-users@xxxxxxxxxxx
>
> Sent by:        aspectj-users-bounces@xxxxxxxxxxx
>
> To:        aspectj-users@xxxxxxxxxxx
> cc:        
> Subject:        [aspectj-users] Oddity with @Around and proceed arguments
>
>
> Hi experts!
>
> I'm a newcomer to this technology, so forgive me if I've missed the
> obvious.  For various reasons, the project I'm working on is interesting
> in incorporating the annotation style for aspect declaration.  I've
> encountered an oddity which I'm unsure about.  In essense I have
> duplicated the @Around example in chapter 9 of the developers notebook
> (http://www.eclipse.org/aspectj/doc/released/adk15notebook/ataspectj-pcadvice.html)
> where each of the following classes are in a separate .java file:
>
>    public class M {
>        public static void main( String[] args ) {
>            C c = new C();
>            c.bar(42);
>        }
>    }
>
>    public class C {
>        public void bar(int i) {
>            System.out.println( i );
>        }
>    }
>
>    @Aspect
>    public class A {
>
>        @Pointcut( "call(void C.bar( int )) && args( i ) " )
>        void fooOfC( int i ) {}
>
>        @Around("fooOfC( i )")
>        public void foo2( ProceedingJoinPoint pjp, int i) {
>            pjp.proceed( new Object[] { pjp.getTarget(), i } );
>            /* Doc doesn't show this ---^^^^^^^^^^^^^^^
>             * Via the doc I should have passed just the int reference
> thus:
>             * pjp.proceed( new Object[] { i } );
>             */
>        }
>    }
>
> When I followed the example by only including the int in the Object
> array, I was getting a ClassCastException which after javap'ing the file
> indicated that the weaver appeared to be expecting two arguments rather
> than one.  The first (and missing arg) appearing to be the instance of
> object to proceed to.  By getting the target from the pjp reference and
> adding it to the array of objects passed, the problem seems to be solved
> and everything worked fine.  So, I'd just like to have confidence that
> what I'm doing is in fact the correct methodology and that this is a
> documentation oversight or alternately, that my limited understanding
> has resulted in me completely bolluxing everything up and things should
> be specified in a different way.
>
> Thanks for your help!!!
>
> =Ron=
>
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
>------------------------------------------------------------------------
>
>_______________________________________________
>aspectj-users mailing list
>aspectj-users@xxxxxxxxxxx
>https://dev.eclipse.org/mailman/listinfo/aspectj-users
>  
>



Back to the top