Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Monitoring all method calls exception

Your pointcut will catch static method calls.  At the call to static
method there is no target instance, and so thisJoinPoint.getTarget()
will return NULL, hence the NPE.  If you want the classname of the
target, use getSignature().getDeclaringType()

You should write !within(mypackage.bookTrading.*) and not
within(!mypackage.bookTrading.*) as the latter will not exclude inner
types and it looks like you have one of those because of the access$0
shown in your output.  I imagine you really also want to exclude
subtypes too, so it would be !within(mypackage.bookTrading..*)

cheers,
Andy.


On 06/11/2007, Rob Austin <austirob@xxxxxxxxxxxxxx> wrote:
>
> Hi,
>
> I want to write an aspect that logs any call to my Package (myPackage) from
> outside of it - those I don't expect in other words.
>
> I'm facing the following problems with my newbie code:
> 1. I  thought I could restrict my advice to  calls made outside of my
> package by using within(! myPackage.bookTrading.* ) , but as you can see in
> the output below, it still seems to include calls made from within my
> package.
>
> 2. Where a call is to a method contained in a jar rather than in code for
> which the source is included in the project, thisJoinPoint
> .getTarget().getClass errors out with a nasty message, something along the
> lines of "Attempt to send a message to a non object value". I assume that
> this behaviour would be expected, but any ideas how I can trap for this
> rather than letting an error be raised.
>
> Really appreciate any help,
>
> Thanks
>
> Rob
>
>
>
> public aspect WatchMethodCalls {
>
>
> pointcut WatchAll(): call(* myPackage ..*.*(..))
> && within(! myPackage.bookTrading.*) && within(! WatchMethodCalls);
>
>
>
> before( ) :  WatchAll( )
>
> {
>     System.out.println("thisJoinPoint.getTarget().getSignature() "
> +thisJoinPointStaticPart .getSignature());
>     System.out.println("thisJoinPoint.getTarget().getSourceLocation() " +
> thisJoinPointStaticPart .getSourceLocation());
>     System.out.println("thisJoinPoint.getTarget().getClass() " +
> thisJoinPoint .getTarget().getClass());
>
>
>
> }
>
> Sample output;
>
> thisJoinPoint.getTarget().getSignature() Vector
> myPackage.bookTrading.BookBuyerAgentMalicious.access$0(BookBuyerAgentMalicious)
> thisJoinPoint.getTarget().getSourceLocation()
> BookBuyerAgentMalicious.java:288
>
> Error occurred in WatchAll:java.lang.NullPointerException
> at
> apoptotic.BlockMethodCalls.ajc$before$apoptotic_BlockMethodCalls$1$2e232b3e
> (BlockMethodCalls.aj:22)
> at
> apoptotic.bookTrading.BookBuyerAgentMalicious$BookNegotiator.action(BookBuyerAgentMalicious.java:288)
> at
> jade.core.behaviours.Behaviour.actionWrapper(Behaviour.java:340)
>
>
>
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
>


Back to the top