Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-dev] Getting null pointer exception when getting class name from Target object in AspectJ

Hi All,

Just to add more to the below email. I am using percflow aspect association and the pointcut is defined on a static method of a class. So, is that the reason why the target object is null. How to get the class name in this scenairo.


Thanks.

Sridhar Thiyagarajan


On Mon, Jun 15, 2015 at 4:47 PM, sridhar thiyagarajan <sridharthiyagarajan@xxxxxxxxx> wrote:
Hello,

I am using AspectJ 1.8.6. PFB the advise method code snippet which am using for performance logging. I am getting NULL POINTER EXCEPTION in the line invocation.getTarget().getClass().getSimpleName().

I am getting method name from the line invocation.getSignature().getName() but not getting the class name from   seeing the method from invocation.getTarget().getClass().getSimpleName().

Have anyone faced this concern ? Please help me.

public Object invoke(final ProceedingJoinPoint invocation) throws Throwable {              
    StopWatch watch = new StopWatch();
    watch.start();
    Object result = null;
    try {
        result =  invocation.proceed();
    } finally {
        watch.stop();
        StringBuilder sb = new StringBuilder();
        sb.append("Method: ")
        .append(invocation.getTarget().getClass().getSimpleName())
        .append(".")
        .append(invocation.getSignature().getName())
        .append("() finished in: ")
        .append(watch.getTime());
        log.log(sb.toString());
    }      
    return result;
}


Many thanks.

Sridhar Thiyagarajan



Back to the top