{"record":{"id":"6121d38ff27a871c","repo":"spring-projects/spring-framework","slug":"expecting-arguments-to-proceed-but-was-passed","errorCode":null,"errorMessage":"Expecting {} arguments to proceed, but was passed {} arguments","messagePattern":"Expecting (.+?) arguments to proceed, but was passed (.+?) arguments","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-aop/src/main/java/org/springframework/aop/aspectj/MethodInvocationProceedingJoinPoint.java","lineNumber":89,"sourceCode":"\t\tthis.methodInvocation = methodInvocation;\n\t}\n\n\n\t@Override\n\tpublic void set$AroundClosure(AroundClosure aroundClosure) {\n\t\tthrow new UnsupportedOperationException();\n\t}\n\n\t@Override\n\tpublic @Nullable Object proceed() throws Throwable {\n\t\treturn this.methodInvocation.invocableClone().proceed();\n\t}\n\n\t@Override\n\tpublic @Nullable Object proceed(Object[] arguments) throws Throwable {\n\t\tAssert.notNull(arguments, \"Argument array passed to proceed cannot be null\");\n\t\tif (arguments.length != this.methodInvocation.getArguments().length) {\n\t\t\tthrow new IllegalArgumentException(\"Expecting \" +\n\t\t\t\t\tthis.methodInvocation.getArguments().length + \" arguments to proceed, \" +\n\t\t\t\t\t\"but was passed \" + arguments.length + \" arguments\");\n\t\t}\n\t\tthis.methodInvocation.setArguments(arguments);\n\t\treturn this.methodInvocation.invocableClone(arguments).proceed();\n\t}\n\n\t/**\n\t * Returns the Spring AOP proxy. Cannot be {@code null}.\n\t */\n\t@Override\n\tpublic Object getThis() {\n\t\treturn this.methodInvocation.getProxy();\n\t}\n\n\t/**\n\t * Returns the Spring AOP target. May be {@code null} if there is no target.\n\t */","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/69bf83ad716d0cfc4b0520a19b4d8b24c79d1538/spring-aop/src/main/java/org/springframework/aop/aspectj/MethodInvocationProceedingJoinPoint.java#L71-L107","documentation":"Thrown by MethodInvocationProceedingJoinPoint.proceed(Object[]) when the supplied argument array length does not match the intercepted method's argument count. Spring replaces the invocation arguments in-place, so the new array must have exactly the same number of elements as the current getArguments().","triggerScenarios":"In an @Around advice, calling pjp.proceed(new Object[]{arg1}) when the target method takes 3 parameters, or calling pjp.proceed(new Object[0]) on a method that takes 2 params.","commonSituations":"Advice that tries to modify or suppress specific arguments and passes the wrong total count, or that builds a partial array from getArgs() without copying all elements.","solutions":["Pass pjp.getArgs() unchanged if you are not modifying arguments, using the no-arg proceed() variant","Build the new array with the same length as pjp.getArgs() and copy/modify individual elements","Validate arguments.length == joinPoint.getArgs().length before calling proceed(arguments)"],"exampleFix":"// before\n@Around(\"execution(* com.example..*(..))\")\npublic Object around(ProceedingJoinPoint pjp) throws Throwable {\n    return pjp.proceed(new Object[]{modifiedArg}); // wrong count\n}\n\n// after\n@Around(\"execution(* com.example..*(..))\")\npublic Object around(ProceedingJoinPoint pjp) throws Throwable {\n    Object[] args = pjp.getArgs();\n    args[0] = modifiedArg;\n    return pjp.proceed(args);\n}","handlingStrategy":"validation","validationCode":"// Validate argument count before calling proceed(Object[])\nObject[] args = pjp.getArgs();\nif (modifiedArgs.length != args.length) {\n    throw new IllegalArgumentException(\n        \"Expected \" + args.length + \" args but got \" + modifiedArgs.length);\n}\npjp.proceed(modifiedArgs);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer pjp.proceed() (no-arg) when not modifying arguments","When modifying, start from pjp.getArgs().clone() and change individual elements — the length stays correct","Never build a new array from scratch with a different length"],"tags":["spring-aop","aspectj","around-advice","proceed"],"backgroundTag":null,"analyzedSha":"69bf83ad716d0cfc4b0520a19b4d8b24c79d1538","analyzedAt":"2026-08-09T15:32:58.770Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}