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

  1. Fix the pointcut expression syntax (balance parentheses, valid designators, correct wildcard patterns).
  2. Call setLocation("myPointcut") before setExpression so the wrapped message names the offending definition.
  3. 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

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


AI-assisted analysis of spring-projects/spring-framework@e8729d0438 (2026-08-04). Data as JSON: /data/errors/93f145cf9df0d4b6.json. Report an issue: GitHub.