spring-projects/spring-framework · error · IllegalStateException

Number of pointcut parameter names must match number of poin

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. A pointcut expression that references bound parameters requires a one-to-one correspondence between names and types; mismatched arrays are a programming error.

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 e8729d0438)

Solutions

  1. Ensure paramNames.length == paramTypes.length before constructing.
  2. Build both arrays from a single source of truth (e.g. a list of parameter descriptors).
  3. Prefer setParameterNames/setParameterTypes with consistent data.

Example fix

// before
new AspectJExpressionPointcut(scope, new String[]{"a"}, new Class[]{int.class, String.class});

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

Strategy: validation

Validate before calling

if (paramNames.length != paramTypes.length) {
    throw new IllegalArgumentException("paramNames and paramTypes length mismatch");
}

Prevention

When it happens

Trigger: Constructing an AspectJExpressionPointcut directly with new AspectJExpressionPointcut(scope, names, types) where names.length != types.length.

Common situations: Programmatic pointcut construction (not via XML/annotation config) where the caller assembles the two arrays separately and they drift out of sync; refactoring that adds a type but forgets the name or vice versa.

Related errors


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