spring-projects/spring-framework · error · IllegalArgumentException
Returning name '{}' is neither a valid argument name nor the
Error message
Returning name '{}' is neither a valid argument name nor the fully-qualified name of a Java type on the classpath. Root cause: {} What it means
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.
Source
Thrown at spring-aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java:310
throw new UnsupportedOperationException("Only afterReturning advice can be used to bind a return value");
}
/**
* We need to hold the returning name at this level for argument binding calculations,
* this method allows the afterReturning advice subclass to set the name.
*/
protected void setReturningNameNoCheck(String name) {
// name could be a variable or a type...
if (isVariableName(name)) {
this.returningName = name;
}
else {
// assume a type
try {
this.discoveredReturningType = ClassUtils.forName(name, getAspectClassLoader());
}
catch (Throwable ex) {
throw new IllegalArgumentException("Returning name '" + name +
"' is neither a valid argument name nor the fully-qualified " +
"name of a Java type on the classpath. Root cause: " + ex);
}
}
}
protected Class<?> getDiscoveredReturningType() {
return this.discoveredReturningType;
}
protected @Nullable Type getDiscoveredReturningGenericType() {
return this.discoveredReturningGenericType;
}
public void setThrowingName(String name) {
throw new UnsupportedOperationException("Only afterThrowing advice can be used to bind a thrown exception");
}
View on GitHub (pinned to e8729d0438)
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.
Example fix
// before <aop:after-returning method="log" returning="Reesult" pointcut="..."/> // after <aop:after-returning method="log" returning="result" pointcut="..."/>
Defensive patterns
Strategy: validation
Validate before calling
// Validate a returning value before setting it: must be an identifier or a loadable type.
String name = returningValue.strip();
boolean ok = AspectJProxyUtils.isVariableName(name);
if (!ok) {
try { ClassUtils.forName(name, aspectClassLoader); ok = true; }
catch (Throwable t) { ok = false; }
}
if (!ok) throw new IllegalArgumentException("Invalid returning value: " + name); Try / catch
try {
((AspectJAfterReturningAdvice) advice).setReturningName(name);
} catch (IllegalArgumentException ex) {
throw new IllegalArgumentException(
"'returning' must be a parameter name or fully-qualified type on the classpath: " + name, ex);
} Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- Throwing name '{}' is neither a valid argument name nor the
- Returning argument name '{}' was not bound in advice argumen
- 'argumentNames' property of AbstractAspectJAdvice contains a
- Only afterReturning advice can be used to bind a return valu
- Advice method [{}] requires {} arguments to be bound by name
AI-assisted analysis of spring-projects/spring-framework@e8729d0438 (2026-08-04).
Data as JSON: /data/errors/6f7f3b717a0002f9.json.
Report an issue: GitHub.