Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[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=




Back to the top