6

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); 
1

1 Answer 1

1

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}

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Fred! From my analyses, it appears there are certain environments / JVM configs where paramNames are available, but it's been a while back now and can't recall the specific details. Thanks for pointing out on the return value, I'd adapted the question from my code and might have left out some bits.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.