{"id":"a62a53792e0673d1","repo":"spring-projects/spring-framework","slug":"mismatch-on-arguments-to-advice-method-point","errorCode":null,"errorMessage":"Mismatch on arguments to advice method [{}]; pointcut expression [{}]","messagePattern":"Mismatch on arguments to advice method \\[(.+?)\\]; pointcut expression \\[(.+?)\\]","errorType":"exception","errorClass":"AopInvocationException","httpStatus":null,"severity":"error","filePath":"spring-aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java","lineNumber":651,"sourceCode":"\tprotected @Nullable Object invokeAdviceMethodWithGivenArgs(@Nullable Object[] args) throws Throwable {\n\t\t@Nullable Object[] actualArgs = args;\n\t\tif (this.aspectJAdviceMethod.getParameterCount() == 0) {\n\t\t\tactualArgs = null;\n\t\t}\n\t\tObject aspectInstance = this.aspectInstanceFactory.getAspectInstance();\n\t\tif (aspectInstance.equals(null)) {\n\t\t\t// Possibly a NullBean -> simply proceed if necessary.\n\t\t\tif (getJoinPoint() instanceof ProceedingJoinPoint pjp) {\n\t\t\t\treturn pjp.proceed();\n\t\t\t}\n\t\t\treturn null;\n\t\t}\n\t\ttry {\n\t\t\tReflectionUtils.makeAccessible(this.aspectJAdviceMethod);\n\t\t\treturn this.aspectJAdviceMethod.invoke(aspectInstance, actualArgs);\n\t\t}\n\t\tcatch (IllegalArgumentException ex) {\n\t\t\tthrow new AopInvocationException(\"Mismatch on arguments to advice method [\" +\n\t\t\t\t\tthis.aspectJAdviceMethod + \"]; pointcut expression [\" +\n\t\t\t\t\tthis.pointcut.getPointcutExpression() + \"]\", ex);\n\t\t}\n\t\tcatch (InvocationTargetException ex) {\n\t\t\tthrow ex.getTargetException();\n\t\t}\n\t}\n\n\t/**\n\t * Overridden in around advice to return proceeding join point.\n\t */\n\tprotected JoinPoint getJoinPoint() {\n\t\treturn currentJoinPoint();\n\t}\n\n\t/**\n\t * Get the current join point match at the join point we are being dispatched on.\n\t */","sourceCodeStart":633,"sourceCodeEnd":669,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/e8729d043887bf0d0baf91e062e909b56eb2b708/spring-aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java#L633-L669","documentation":"Thrown by invokeAdviceMethodWithGivenArgs (line 650-654) when Method.invoke raises IllegalArgumentException, wrapping it as AopInvocationException. The advice method's reflective invocation could not accept the constructed argument array - a type or arity mismatch between the bound arguments and the advice method signature.","triggerScenarios":"The bound argument types do not match the advice method's declared parameter types at invocation: e.g. a pointcut binds an Object but the advice parameter is a narrower type that the value isn't assignable to; a null returned for a primitive parameter; returning/throwing values whose runtime type doesn't match the declared parameter type.","commonSituations":"Pointcut returning a supertype while advice declares a narrower subtype; after-throwing where the thrown exception isn't assignable to the declared exception parameter; nulls being bound into primitive parameters; mismatches between the pointcut's declared binding types and the advice signature.","solutions":["Align the advice parameter types with what the pointcut/returning/throwing actually supplies (widen the parameter type to match the bound value).","For returning/throwing narrowing, ensure the bound value is assignable to the declared parameter type at every matched join point.","Avoid primitive advice parameters where a null may be bound; use wrapper types.","Re-check the pointcut expression quoted in the message against the advice signature."],"exampleFix":"// before: returning narrows to Result but the pointcut may return a subtype Object\n@AfterReturning(value = \"execution(* svc.*(..))\", returning = \"ret\")\npublic void log(Result ret) { ... }\n// after\n@AfterReturning(value = \"execution(* svc.*(..))\", returning = \"ret\")\npublic void log(Object ret) { ... }","handlingStrategy":"validation","validationCode":"// Validate that every advice parameter type is compatible with what will be bound into it.\nClass<?>[] ptypes = adviceMethod.getParameterTypes();\n// e.g. for returning/throwing narrowing:\nif (returningName != null) {\n    int i = indexOf(ptypes, adviceParamNames, returningName);\n    if (!Object.class.isAssignableFrom(ptypes[i]) && !isAssignableFromAllMatchedReturns(pointcut, ptypes[i])) {\n        throw new IllegalStateException(\"Advice param type \" + ptypes[i] + \" too narrow for bound return value\");\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    return advice.invokeAdviceMethodWithGivenArgs(args);\n} catch (AopInvocationException ex) {\n    if (ex.getMessage().startsWith(\"Mismatch on arguments to advice method\")) {\n        // inspect bound arg types vs advice parameter types and report\n        throw new AopInvocationException(\"Type/arity mismatch invoking \" + adviceMethod, ex);\n    }\n    throw ex;\n}","preventionTips":["Declare advice parameter types wide enough for every value the pointcut can bind.","Avoid primitive advice parameters where nulls may be bound; use wrappers.","For returning/throwing narrowing, ensure assignability at every matched join point.","Re-check the pointcut expression (quoted in the message) against the advice signature."],"tags":["spring-aop","aspectj","argument-binding","type-mismatch","runtime"],"analyzedSha":"e8729d043887bf0d0baf91e062e909b56eb2b708","analyzedAt":"2026-08-04T19:07:39.725Z","schemaVersion":2}