spring-projects/spring-framework · error · IllegalArgumentException
Invalid expression at location
Error message
Invalid expression at location [{location}]: {ex} What it means
Thrown by AbstractExpressionPointcut.setExpression (line 58-71) when the subclass's onSetExpression(expression) raises an IllegalArgumentException (e.g. a malformed AspectJ pointcut expression) AND a location string was previously set via setLocation(...). The original parse error is re-thrown wrapped with the location prefix to make debugging easier; if no location was set, the raw exception propagates.
Solutions
- Correct the pointcut expression syntax - validate it against AspectJ grammar (e.g. 'execution(* com.example.Service.*(..))').
- Ensure all referenced types are on the classpath and fully qualified where needed.
- If the message includes a location, inspect that source (XML id / programmatic label) to find which pointcut is misconfigured.
- Use the AspectJ parser/IDE plugin or Spring's PointcutExpression unit tests to confirm validity before deployment.
Example fix
// before
AspectJExpressionPointcut pc = new AspectJExpressionPointcut();
pc.setLocation("servicePointcut");
pc.setExpression("executon(* com.example.Service.*(..))"); // typo
// after
pc.setExpression("execution(* com.example.Service.*(..))"); Defensive patterns
Strategy: validation
Validate before calling
AspectJExpressionPointcut pc = new AspectJExpressionPointcut();
try {
pc.setExpression(expr); // throws on invalid
} catch (IllegalArgumentException e) {
// log and reject the configuration
} Try / catch
try {
pc.setExpression(candidateExpr);
} catch (IllegalArgumentException e) {
logger.warn("Invalid pointcut expression: " + candidateExpr, e);
// fall back to a safe default expression
} Prevention
- Validate AspectJ expressions in unit tests before deploying config.
- Set a location string via setLocation for clearer error messages.
- Fully qualify types and double-check execution/within/args syntax.
When it happens
Trigger: Configuring an AspectJExpressionPointcut (or other AbstractExpressionPointcut subclass) with a syntactically invalid expression - e.g. 'execution(()' , 'executon(* ..*(..))', undefined type references - and having called setLocation(...) to tag the source. onSetExpression parses the expression immediately and throws.
Common situations: Typos in AspectJ pointcut expressions (execution/within/args). Referencing a type or method signature that does not exist or is not on the classpath. Copying an expression from a newer AspectJ version into an older Spring. XML-configured pointcuts where the location is the XML resource id.
Related errors
- Failed to resolve pointcut expression in
- Must set property 'expression' before attempting to match
- Number of pointcut parameter names must match number of…
- Advice must be declared inside an aspect type: Offending…
- 'argumentNames' property of AbstractAspectJAdvice contains…
AI-assisted analysis of spring-projects/spring-framework@69bf83ad71 (2026-08-09).
Data as JSON: /api/errors/93f145cf9df0d4b6.
Report an issue: GitHub.
Appendix: 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 69bf83ad71)