Skip to main content

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

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,
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)

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(
at jade.core.behaviours.Behaviour.actionWrapper(



Back to the top