{"record":{"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/69bf83ad716d0cfc4b0520a19b4d8b24c79d1538/spring-aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java#L633-L669","documentation":"Thrown by invokeAdviceMethodWithGivenArgs (line 650-654) as an AopInvocationException wrapping an IllegalArgumentException from Method.invoke. The underlying cause is that the assembled argument array does not match the advice method's formal parameters at reflective invocation time (wrong count or incompatible types). The message includes both the advice method and the pointcut expression to aid diagnosis.","triggerScenarios":"The bound argument values (from pointcut match + returning + throwing) have types incompatible with the advice method's declared parameter types — e.g. an args() binding yields a String but the parameter is Integer, or returning binds a value whose runtime type is not assignable to the declared parameter type. Distinct from error [11] (which is about count); this is about the reflective invoke failing.","commonSituations":"Pointcut binds a variable whose runtime type does not match the advice parameter type, the returning type restriction is looser than the parameter, or a generic/erasure mismatch. Common after changing a target method's signature so the bound value's type changes, or after a refactoring that alters which value an args() variable captures.","solutions":["Inspect the wrapped IllegalArgumentException cause to see which argument failed type conversion.","Make the advice parameter type a supertype of the bound value (e.g. Object instead of a narrow type).","For returning, use a type restriction that matches the actual return type, or widen the parameter.","Verify args()/this()/target() bindings correspond in type and order to the advice parameters."],"exampleFix":"// before — parameter type narrower than bound value\n@AfterReturning(pointcut=\"execution(* svc.*(..))\", returning=\"r\")\npublic void after(String r) { ... } // but target returns Integer -> ClassCastException at invoke\n\n// after — widen the parameter type\n@AfterReturning(pointcut=\"execution(* svc.*(..))\", returning=\"r\")\npublic void after(Object r) { ... }","handlingStrategy":"try-catch","validationCode":"import java.lang.reflect.Method;\n\n// Pre-check assignable types between bound values and advice params (best-effort for returning).\nvoid assertReturningTypeCompatible(Method adviceMethod, String returningName, Class<?> returnType) {\n    String[] names = new org.springframework.core.DefaultParameterNameDiscoverer().getParameterNames(adviceMethod);\n    Class<?>[] types = adviceMethod.getParameterTypes();\n    for (int i = 0; names != null && i < names.length; i++) {\n        if (names[i].equals(returningName) && !types[i].isAssignableFrom(returnType)) {\n            throw new IllegalStateException(\"returning param type \" + types[i] + \" cannot accept \" + returnType);\n        }\n    }\n}","typeGuard":"boolean returningTypeAccepts(Method m, String returningName, Class<?> returnType) {\n    String[] names = new org.springframework.core.DefaultParameterNameDiscoverer().getParameterNames(m);\n    Class<?>[] types = m.getParameterTypes();\n    for (int i = 0; names != null && i < names.length; i++) {\n        if (names[i].equals(returningName)) return types[i].isAssignableFrom(returnType);\n    }\n    return false;\n}","tryCatchPattern":"import org.springframework.aop.AopInvocationException;\ntry {\n    proxy.businessMethod();\n} catch (AopInvocationException ex) {\n    // ex.getMessage() contains the advice method + pointcut expression;\n    // cause is IllegalArgumentException naming the offending argument\n    Throwable cause = ex.getCause();\n    // widen the parameter type or fix the binding, then retry\n}","preventionTips":["Use widening parameter types (Object) for returning/args bindings to avoid ClassCastException at invoke.","Keep the pointcut binding variable types aligned with advice parameter types.","Cover advice paths with integration tests invoking the real proxy."],"tags":["spring-aop","aspectj","argument-binding","runtime","type-mismatch"],"backgroundTag":null,"analyzedSha":"69bf83ad716d0cfc4b0520a19b4d8b24c79d1538","analyzedAt":"2026-08-09T15:32:58.770Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}