Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AspectJ MethodSignature returning null for getParameterNames()

I have an aspect that does various computations based on the target method's details, and therefore extracts these upfront as follows:

    @Around("execution(* com.xyz.service.AccountService.*(..))")
public void validateParams(ProceedingJoinPoint joinPoint) throws Throwable {
    final MethodSignature signature = (MethodSignature) joinPoint.getSignature();

    final String methodName = signature.getName();
    final String[] parameterNames = signature.getParameterNames();
    final Object[] arguments = joinPoint.getArgs();
    ...
    ...
    ...
    joinPoint.proceed();
}

Of the extracted details, all reflect the expected info except parameterNames which always returns null. I would expect it to return {accountDetails} as per the signature below. Would anyone know what I may be missing, or is this a bug?

Here's the signature of the target method I am working against:

Long createAccount(RequestAccountDetails accountDetails);
like image 964
Michael-7 Avatar asked Jan 14 '12 03:01

Michael-7


1 Answers

works for me:

@Aspect
public class MyAspect {

    @Around("execution(* *(..)) && !within(MyAspect)")
    public Object validateParams(ProceedingJoinPoint joinPoint) throws Throwable {
        final MethodSignature signature = (MethodSignature) joinPoint.getSignature();

        final String[] parameterNames = signature.getParameterNames();
        for (String string : parameterNames) {
            System.out.println("paramName: " + string);
        }

        return joinPoint.proceed();

    }
}

output: paramName: accountDetails

I have changed the signature of validateParams to: public Object validateParams(ProceedingJoinPoint joinPoint) throws Throwable because createAccount() returns a Long. Otherwise I get the error: applying to join point that doesnt return void: {0}

like image 62
Fred Avatar answered Oct 20 '22 13:10

Fred