{"record":{"id":"c87802cf4fbf4333","repo":"spring-projects/spring-framework","slug":"advice-method-requires-arguments-to-be-bou","errorCode":null,"errorMessage":"Advice method [{}] requires {} arguments to be bound by name, but the argument names were not specified and could not be discovered.","messagePattern":"Advice method \\[(.+?)\\] requires (.+?) arguments to be bound by name, but the argument names were not specified and could not be discovered\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"spring-aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java","lineNumber":441,"sourceCode":"\t\tif (JoinPoint.StaticPart.class == candidateParameterType) {\n\t\t\tthis.joinPointStaticPartArgumentIndex = 0;\n\t\t\treturn true;\n\t\t}\n\t\telse {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\tprivate void bindArgumentsByName(int numArgumentsExpectingToBind) {\n\t\tif (this.argumentNames == null) {\n\t\t\tthis.argumentNames = createParameterNameDiscoverer().getParameterNames(this.aspectJAdviceMethod);\n\t\t}\n\t\tif (this.argumentNames != null) {\n\t\t\t// We have been able to determine the arg names.\n\t\t\tbindExplicitArguments(numArgumentsExpectingToBind);\n\t\t}\n\t\telse {\n\t\t\tthrow new IllegalStateException(\"Advice method [\" + this.aspectJAdviceMethod.getName() + \"] \" +\n\t\t\t\t\t\"requires \" + numArgumentsExpectingToBind + \" arguments to be bound by name, but \" +\n\t\t\t\t\t\"the argument names were not specified and could not be discovered.\");\n\t\t}\n\t}\n\n\t/**\n\t * Create a ParameterNameDiscoverer to be used for argument binding.\n\t * <p>The default implementation creates a {@link DefaultParameterNameDiscoverer}\n\t * and adds a specifically configured {@link AspectJAdviceParameterNameDiscoverer}.\n\t */\n\tprotected ParameterNameDiscoverer createParameterNameDiscoverer() {\n\t\t// We need to discover them, or if that fails, guess,\n\t\t// and if we can't guess with 100% accuracy, fail.\n\t\tDefaultParameterNameDiscoverer discoverer = new DefaultParameterNameDiscoverer();\n\t\tAspectJAdviceParameterNameDiscoverer adviceParameterNameDiscoverer =\n\t\t\t\tnew AspectJAdviceParameterNameDiscoverer(this.pointcut.getExpression());\n\t\tadviceParameterNameDiscoverer.setReturningName(this.returningName);\n\t\tadviceParameterNameDiscoverer.setThrowingName(this.throwingName);","sourceCodeStart":423,"sourceCodeEnd":459,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/69bf83ad716d0cfc4b0520a19b4d8b24c79d1538/spring-aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java#L423-L459","documentation":"Thrown by bindArgumentsByName (line 432-444) when the advice method has parameters that must be bound by name (numUnboundArgs > 0) but this.argumentNames is null — i.e. setArgumentNames was never called AND the ParameterNameDiscoverer chain returned null. The discoverer returns null when it cannot unambiguously deduce names (see AspectJAdviceParameterNameDiscoverer). Without names, pointcut parameter binding is impossible, so Spring fails fast.","triggerScenarios":"An advice method with one or more non-joinpoint parameters, compiled WITHOUT -parameters (and without -debug variable info), whose pointcut expression does not unambiguously reveal the binding. For example @AfterReturning(pointcut=\"execution(* *(..))\", returning=\"r\") on a method after(Object r) compiled without parameter names. Also when the pointcut expression has no bindable forms (no args(), this(), target(), @annotation()) to deduce from.","commonSituations":"Java 8+ project not compiled with -parameters, obfuscated/stripped bytecode, advice with multiple unbound parameters that the heuristic algorithm cannot disambiguate, or a pointcut that uses no binding forms. Common when moving from annotation-style binding (where names came from debug info) to a stricter toolchain.","solutions":["Compile with -parameters (javac -parameters / Maven compiler-plugin <parameters>true</parameters>) so declared names are available to DefaultParameterNameDiscoverer.","Explicitly specify arg-names in XML or use binding annotations so setArgumentNames is called.","Rewrite the pointcut to use binding forms (args(x), this(x), @annotation(x)) that the discoverer can interpret.","Reduce the number of unbound parameters so the heuristic algorithm can disambiguate."],"exampleFix":"// before — advice compiled without -parameters; pointcut has no binding form\n@AfterReturning(\"execution(* svc.*(..))\")\npublic void after(Object retVal) { ... }\n\n// after — bind via returning and compile with -parameters, OR name explicitly\n@AfterReturning(pointcut=\"execution(* svc.*(..))\", returning=\"retVal\")\npublic void after(Object retVal) { ... }\n// plus pom.xml: <maven.compiler.parameters>true</maven.compiler.parameters>","handlingStrategy":"validation","validationCode":"import org.springframework.core.DefaultParameterNameDiscoverer;\nimport java.lang.reflect.Method;\n\n// Pre-check that parameter names are discoverable before registering advice.\nboolean namesDiscoverable(Method adviceMethod) {\n    String[] names = new DefaultParameterNameDiscoverer().getParameterNames(adviceMethod);\n    return names != null;\n}\n// Build advice only when this returns true, else require explicit arg-names.","typeGuard":"boolean hasBindableParameterNames(Method m, String[] explicitArgNames) {\n    if (explicitArgNames != null) return true;\n    return new org.springframework.core.DefaultParameterNameDiscoverer().getParameterNames(m) != null;\n}","tryCatchPattern":"try {\n    advice.getPointcut(); // triggers calculateArgumentBindings\n} catch (IllegalStateException ex) {\n    if (ex.getMessage().contains(\"could not be discovered\")) {\n        // enable -parameters or supply arg-names, then retry\n    } else { throw ex; }\n}","preventionTips":["Compile all modules containing @Aspect classes with -parameters (maven.compiler.parameters=true).","Supply arg-names explicitly when parameter names may be unavailable.","Prefer pointcut expressions with binding forms (args(), this(), @annotation()) so discovery can succeed."],"tags":["spring-aop","aspectj","parameter-names","argument-binding","compiler"],"backgroundTag":null,"analyzedSha":"69bf83ad716d0cfc4b0520a19b4d8b24c79d1538","analyzedAt":"2026-08-09T15:32:58.770Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}