{"id":"6f7f3b717a0002f9","repo":"spring-projects/spring-framework","slug":"returning-name-is-neither-a-valid-argument-na","errorCode":null,"errorMessage":"Returning name '{}' is neither a valid argument name nor the fully-qualified name of a Java type on the classpath. Root cause: {}","messagePattern":"Returning name '(.+?)' is neither a valid argument name nor the fully-qualified name of a Java type on the classpath\\. Root cause: (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java","lineNumber":310,"sourceCode":"\t\tthrow new UnsupportedOperationException(\"Only afterReturning advice can be used to bind a return value\");\n\t}\n\n\t/**\n\t * We need to hold the returning name at this level for argument binding calculations,\n\t * this method allows the afterReturning advice subclass to set the name.\n\t */\n\tprotected void setReturningNameNoCheck(String name) {\n\t\t// name could be a variable or a type...\n\t\tif (isVariableName(name)) {\n\t\t\tthis.returningName = name;\n\t\t}\n\t\telse {\n\t\t\t// assume a type\n\t\t\ttry {\n\t\t\t\tthis.discoveredReturningType = ClassUtils.forName(name, getAspectClassLoader());\n\t\t\t}\n\t\t\tcatch (Throwable ex) {\n\t\t\t\tthrow new IllegalArgumentException(\"Returning name '\" + name +\n\t\t\t\t\t\t\"' is neither a valid argument name nor the fully-qualified \" +\n\t\t\t\t\t\t\"name of a Java type on the classpath. Root cause: \" + ex);\n\t\t\t}\n\t\t}\n\t}\n\n\tprotected Class<?> getDiscoveredReturningType() {\n\t\treturn this.discoveredReturningType;\n\t}\n\n\tprotected @Nullable Type getDiscoveredReturningGenericType() {\n\t\treturn this.discoveredReturningGenericType;\n\t}\n\n\tpublic void setThrowingName(String name) {\n\t\tthrow new UnsupportedOperationException(\"Only afterThrowing advice can be used to bind a thrown exception\");\n\t}\n","sourceCodeStart":292,"sourceCodeEnd":328,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/e8729d043887bf0d0baf91e062e909b56eb2b708/spring-aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java#L292-L328","documentation":"Thrown by setReturningNameNoCheck (line 299-315) when the returning value is not a Java variable name AND ClassUtils.forName cannot load it as a type on the aspect's classloader. Spring treats a non-identifier returning value as a fully-qualified type used to narrow the matched return type; if it is neither a name nor a loadable type, binding is impossible.","triggerScenarios":"Setting 'returning' to a string that is neither a valid Java identifier (e.g. '123', 'a.b.c' where c isn't a class) nor a fully-qualified class name resolvable by the aspect ClassLoader (typo, missing dependency, wrong package).","commonSituations":"Typo in the returning attribute; specifying a simple class name instead of fully-qualified; the return-narrowing type lives in a jar not on the classpath; refactoring that renamed/moved the return type without updating the aspect XML/annotation.","solutions":["If returning should bind a parameter, use the exact advice parameter name (a valid Java identifier).","If returning is meant to narrow by type, supply the fully-qualified type name and verify it is on the classpath.","Fix typos and package names; ensure the containing jar is a dependency.","Remove the returning attribute if no return binding/narrowing is intended."],"exampleFix":"// before\n<aop:after-returning method=\"log\" returning=\"Reesult\" pointcut=\"...\"/>\n// after\n<aop:after-returning method=\"log\" returning=\"result\" pointcut=\"...\"/>","handlingStrategy":"validation","validationCode":"// Validate a returning value before setting it: must be an identifier or a loadable type.\nString name = returningValue.strip();\nboolean ok = AspectJProxyUtils.isVariableName(name);\nif (!ok) {\n    try { ClassUtils.forName(name, aspectClassLoader); ok = true; }\n    catch (Throwable t) { ok = false; }\n}\nif (!ok) throw new IllegalArgumentException(\"Invalid returning value: \" + name);","typeGuard":null,"tryCatchPattern":"try {\n    ((AspectJAfterReturningAdvice) advice).setReturningName(name);\n} catch (IllegalArgumentException ex) {\n    throw new IllegalArgumentException(\n        \"'returning' must be a parameter name or fully-qualified type on the classpath: \" + name, ex);\n}","preventionTips":["Use the exact advice parameter name as the returning value when binding.","When narrowing by type, copy the fully-qualified type name and verify the jar is present.","Re-run aspect config checks after refactoring return types."],"tags":["spring-aop","aspectj","after-returning","argument-binding","classpath"],"analyzedSha":"e8729d043887bf0d0baf91e062e909b56eb2b708","analyzedAt":"2026-08-04T19:07:39.725Z","schemaVersion":2}