{"record":{"id":"ed9e945dcea9de3b","repo":"spring-projects/spring-framework","slug":"throwing-argument-name-was-not-bound-in-advic","errorCode":null,"errorMessage":"Throwing argument name '{}' was not bound in advice arguments","messagePattern":"Throwing argument name '(.+?)' was not bound in advice arguments","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"spring-aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java","lineNumber":499,"sourceCode":"\t\t\tthis.argumentBindings.put(this.argumentNames[i], i);\n\t\t}\n\n\t\t// Check that returning and throwing were in the argument names list if\n\t\t// specified, and find the discovered argument types.\n\t\tif (this.returningName != null) {\n\t\t\tif (!this.argumentBindings.containsKey(this.returningName)) {\n\t\t\t\tthrow new IllegalStateException(\"Returning argument name '\" + this.returningName +\n\t\t\t\t\t\t\"' was not bound in advice arguments\");\n\t\t\t}\n\t\t\telse {\n\t\t\t\tInteger index = this.argumentBindings.get(this.returningName);\n\t\t\t\tthis.discoveredReturningType = this.aspectJAdviceMethod.getParameterTypes()[index];\n\t\t\t\tthis.discoveredReturningGenericType = this.aspectJAdviceMethod.getGenericParameterTypes()[index];\n\t\t\t}\n\t\t}\n\t\tif (this.throwingName != null) {\n\t\t\tif (!this.argumentBindings.containsKey(this.throwingName)) {\n\t\t\t\tthrow new IllegalStateException(\"Throwing argument name '\" + this.throwingName +\n\t\t\t\t\t\t\"' was not bound in advice arguments\");\n\t\t\t}\n\t\t\telse {\n\t\t\t\tInteger index = this.argumentBindings.get(this.throwingName);\n\t\t\t\tthis.discoveredThrowingType = this.aspectJAdviceMethod.getParameterTypes()[index];\n\t\t\t}\n\t\t}\n\n\t\t// configure the pointcut expression accordingly.\n\t\tconfigurePointcutParameters(this.argumentNames, argumentIndexOffset);\n\t}\n\n\t/**\n\t * All parameters from argumentIndexOffset onwards are candidates for\n\t * pointcut parameters - but returning and throwing vars are handled differently\n\t * and must be removed from the list if present.\n\t */\n\tprivate void configurePointcutParameters(String[] argumentNames, int argumentIndexOffset) {","sourceCodeStart":481,"sourceCodeEnd":517,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/69bf83ad716d0cfc4b0520a19b4d8b24c79d1538/spring-aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java#L481-L517","documentation":"Thrown by bindExplicitArguments (line 497-501) when throwingName is set but does not appear as a key in the computed argumentBindings map. The throwing name must match one of the advice method's parameter names so Spring knows which slot receives the thrown exception. A mismatch means the configured 'throwing' cannot be matched to a parameter.","triggerScenarios":"Configuring throwing=\"ex\" but the advice method's exception parameter is named differently (e.g. 'error'), or parameter discovery returned a name that does not equal throwing. Common when the parameter name and throwing attribute drift apart.","commonSituations":"Renaming an advice parameter without updating the throwing attribute (or vice versa), compiling without -parameters so discovered names diverge, or XML/annotation mismatch after refactoring.","solutions":["Ensure the throwing name exactly matches the advice method's Throwable parameter name.","Compile with -parameters so the real parameter name is discovered and matches throwing.","If using arg-names, confirm it includes the throwing name.","Align XML 'throwing' with the @AfterThrowing(throwing=) value and the method signature."],"exampleFix":"// before — throwing name does not match the parameter\n@AfterThrowing(pointcut=\"execution(* svc.*(..))\", throwing=\"ex\")\npublic void onError(RuntimeException error) { ... }\n\n// after — names agree\n@AfterThrowing(pointcut=\"execution(* svc.*(..))\", throwing=\"error\")\npublic void onError(RuntimeException error) { ... }","handlingStrategy":"validation","validationCode":"import java.lang.reflect.Method;\nimport java.util.Arrays;\n\nvoid assertThrowingNameBound(Method adviceMethod, String throwingName, String[] discoveredNames) {\n    String[] names = discoveredNames != null ? discoveredNames\n        : new org.springframework.core.DefaultParameterNameDiscoverer().getParameterNames(adviceMethod);\n    if (names == null || !Arrays.asList(names).contains(throwingName)) {\n        throw new IllegalStateException(\"throwing '\" + throwingName + \"' not found among params \" + Arrays.toString(names));\n    }\n}","typeGuard":"boolean throwingNameMatchesParam(Method m, String throwingName) {\n    String[] names = new org.springframework.core.DefaultParameterNameDiscoverer().getParameterNames(m);\n    return names != null && java.util.Arrays.asList(names).contains(throwingName);\n}","tryCatchPattern":"try {\n    advice.getPointcut();\n} catch (IllegalStateException ex) {\n    if (ex.getMessage().contains(\"Throwing argument name\") && ex.getMessage().contains(\"not bound\")) {\n        // align the throwing attribute with the actual parameter name\n    } else { throw ex; }\n}","preventionTips":["Keep the throwing attribute identical to the Throwable parameter name.","Compile with -parameters so the discovered name matches.","Update the throwing attribute when renaming the exception parameter."],"tags":["spring-aop","aspectj","after-throwing","argument-binding","naming"],"backgroundTag":null,"analyzedSha":"69bf83ad716d0cfc4b0520a19b4d8b24c79d1538","analyzedAt":"2026-08-09T15:32:58.770Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}