spring-projects/spring-framework · error · IllegalStateException

Number of pointcut parameter names must match number of…

Error message

Number of pointcut parameter names must match number of pointcut parameter types

What it means

Thrown by the AspectJExpressionPointcut constructor when the paramNames and paramTypes arrays have different lengths. Each pointcut parameter requires both a name and a type, and they must correspond positionally; mismatched lengths are a configuration bug.

Solutions

  1. Ensure paramNames.length == paramTypes.length before constructing the pointcut
  2. Use setParameterNames() and setParameterTypes() separately with carefully built arrays
  3. Build the name and type arrays together from a single source (e.g., a list of param descriptors)

Example fix

// before
new AspectJExpressionPointcut(scope,
    new String[]{"a", "b"},
    new Class<?>[]{String.class}); // 2 names, 1 type

// after
new AspectJExpressionPointcut(scope,
    new String[]{"a", "b"},
    new Class<?>[]{String.class, Integer.class});
Defensive patterns

Strategy: validation

Validate before calling

// Validate array lengths match before constructing the pointcut
if (paramNames.length != paramTypes.length) {
    throw new IllegalArgumentException(
        "paramNames length (" + paramNames.length + ") != paramTypes length (" + paramTypes.length + ")");
}
AspectJExpressionPointcut pc = new AspectJExpressionPointcut(scope, paramNames, paramTypes);

Prevention

When it happens

Trigger: Calling new AspectJExpressionPointcut(scope, new String[]{"a","b"}, new Class<?>[]{String.class}) — 2 names but 1 type.

Common situations: Programmatic pointcut construction with buggy array initialization, or copy-paste errors when building parameter arrays.

Related errors


AI-assisted analysis of spring-projects/spring-framework@69bf83ad71 (2026-08-09). Data as JSON: /api/errors/8b8cf01c20e3b646. Report an issue: GitHub.

Appendix: source

Thrown at spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJExpressionPointcut.java:134

	private transient volatile boolean pointcutParsingFailed;


	/**
	 * Create a new default AspectJExpressionPointcut.
	 */
	public AspectJExpressionPointcut() {
	}

	/**
	 * Create a new AspectJExpressionPointcut with the given settings.
	 * @param declarationScope the declaration scope for the pointcut
	 * @param paramNames the parameter names for the pointcut
	 * @param paramTypes the parameter types for the pointcut
	 */
	public AspectJExpressionPointcut(Class<?> declarationScope, String[] paramNames, Class<?>[] paramTypes) {
		setPointcutDeclarationScope(declarationScope);
		if (paramNames.length != paramTypes.length) {
			throw new IllegalStateException(
					"Number of pointcut parameter names must match number of pointcut parameter types");
		}
		this.pointcutParameterNames = paramNames;
		this.pointcutParameterTypes = paramTypes;
	}


	/**
	 * Set the declaration scope for the pointcut.
	 */
	public void setPointcutDeclarationScope(Class<?> pointcutDeclarationScope) {
		this.pointcutDeclarationScope = pointcutDeclarationScope;
		this.aspectCompiledByAjc = compiledByAjc(pointcutDeclarationScope);
	}

	/**
	 * Set the parameter names for the pointcut.
	 */

View on GitHub (pinned to 69bf83ad71)