spring-projects/spring-framework · error · IllegalArgumentException
Invalid expression at location [{location}]: {ex}
Error message
Invalid expression at location [{location}]: {ex} What it means
AbstractExpressionPointcut.setExpression catches an IllegalArgumentException thrown by onSetExpression (typically the AspectJ pointcut parser rejecting malformed syntax) and, when a debug location was set via setLocation, rethrows it with the location prepended for easier diagnosis. The original parse exception is the cause.
Source
Thrown at spring-aop/src/main/java/org/springframework/aop/support/AbstractExpressionPointcut.java:66
/**
* Return location information about the pointcut expression
* if available. This is useful in debugging.
* @return location information as a human-readable String,
* or {@code null} if none is available
*/
public @Nullable String getLocation() {
return this.location;
}
public void setExpression(@Nullable String expression) {
this.expression = expression;
try {
onSetExpression(expression);
}
catch (IllegalArgumentException ex) {
// Fill in location information if possible.
if (this.location != null) {
throw new IllegalArgumentException("Invalid expression at location [" + this.location + "]: " + ex);
}
else {
throw ex;
}
}
}
/**
* Called when a new pointcut expression is set.
* The expression should be parsed at this point if possible.
* <p>This implementation is empty.
* @param expression the expression to set
* @throws IllegalArgumentException if the expression is invalid
* @see #setExpression
*/
protected void onSetExpression(@Nullable String expression) throws IllegalArgumentException {
}
View on GitHub (pinned to e8729d0438)
Solutions
- Fix the pointcut expression syntax (balance parentheses, valid designators, correct wildcard patterns).
- Call setLocation("myPointcut") before setExpression so the wrapped message names the offending definition.
- Validate expressions in a unit test using AspectJExpressionPointcut before deploying.
Example fix
// before
AspectJExpressionPointcut pc = new AspectJExpressionPointcut();
pc.setLocation("servicePointcut");
pc.setExpression("execution(* com.acme.*.bar("); // unbalanced -> error 112
// after
pc.setExpression("execution(* com.acme..*.*(..))"); Defensive patterns
Strategy: try-catch
Validate before calling
AspectJExpressionPointcut pc = new AspectJExpressionPointcut();
pc.setLocation("test");
try {
pc.setExpression(expr);
} catch (IllegalArgumentException ex) {
// expr is invalid; reject configuration at load time
} Try / catch
try {
pointcut.setExpression(expr);
} catch (IllegalArgumentException ex) {
log.error("Invalid pointcut expression: {}", expr, ex);
throw ex;
} Prevention
- Always call setLocation before setExpression to improve error messages.
- Unit-test pointcut expressions with a quick AspectJExpressionPointcut smoke test.
- Lint expression strings at config-load time.
When it happens
Trigger: Calling pointcut.setExpression("execution(* com.acme.*.bar(") (unbalanced parenthesis) on an expression pointcut that had setLocation("fooPointcut") called beforehand.
Common situations: Typos in AspectJ execution()/within() expressions; copy-pasting a pointcut from documentation with smart quotes; mismatched wildcards; upgrading Spring/AspectJ versions that tighten parsing.
Related errors
- Number of pointcut parameter names must match number of poin
- Must set property 'expression' before attempting to match
- MethodInvocation is not a Spring ProxyMethodInvocation: {}
- 'argumentNames' property of AbstractAspectJAdvice contains a
- Only afterReturning advice can be used to bind a return valu
AI-assisted analysis of spring-projects/spring-framework@e8729d0438 (2026-08-04).
Data as JSON: /data/errors/93f145cf9df0d4b6.json.
Report an issue: GitHub.