AspectJ MethodSignature returns null for getParameterNames ()

I have an aspect that performs various calculations based on the data of the target method and therefore extracts them 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(); } 

From the extracted details, all reflect the expected information, except for parameterNames, which always returns null. I expect it to return {accountDetails} according to the captions below. Does anyone know what I can lose, or is this a mistake?

Here is the signature of the target method I'm working with:

 Long createAccount(RequestAccountDetails accountDetails); 
+6
source share
1 answer

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 changed the signature of validateParams to: public Object validateParams(ProceedingJoinPoint joinPoint) throws Throwable because createAccount() returns Long. Otherwise, I get an error: applying to join point that doesnt return void: {0}

+1
source

Source: https://habr.com/ru/post/905959/


All Articles