spring-projects/spring-framework · error · IllegalStateException

Failed to find advice method on deserialization

Error message

Failed to find advice method on deserialization

What it means

Thrown by InstantiationModelAwarePointcutAdvisorImpl.readObject() during Java deserialization when the advice method (stored by name, declaring class, and parameter types) cannot be re-resolved via Class.getMethod. This happens when the aspect class on the deserializing JVM no longer has a method with the exact same name and parameter signature — e.g. the aspect was refactored between serialization and deserialization.

Source

Thrown at spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/InstantiationModelAwarePointcutAdvisorImpl.java:246

					this.isBeforeAdvice = true;
					this.isAfterAdvice = false;
				}
				case AtAfter, AtAfterReturning, AtAfterThrowing -> {
					this.isBeforeAdvice = false;
					this.isAfterAdvice = true;
				}
			}
		}
	}


	private void readObject(ObjectInputStream inputStream) throws IOException, ClassNotFoundException {
		inputStream.defaultReadObject();
		try {
			this.aspectJAdviceMethod = this.declaringClass.getMethod(this.methodName, this.parameterTypes);
		}
		catch (NoSuchMethodException ex) {
			throw new IllegalStateException("Failed to find advice method on deserialization", ex);
		}
	}

	@Override
	public String toString() {
		return "InstantiationModelAwarePointcutAdvisor: expression [" + getDeclaredPointcut().getExpression() +
				"]; advice method [" + this.aspectJAdviceMethod + "]; perClauseKind=" +
				this.aspectInstanceFactory.getAspectMetadata().getAjType().getPerClause().getKind();
	}


	/**
	 * Pointcut implementation that changes its behavior when the advice is instantiated.
	 * Note that this is a <i>dynamic</i> pointcut; otherwise it might be optimized out
	 * if it does not at first match statically.
	 */
	private static final class PerTargetInstantiationModelPointcut extends DynamicMethodMatcherPointcut {

View on GitHub (pinned to e8729d0438)

Solutions

  1. Ensure the aspect class version on the deserializing side has the exact same advice method name and parameter types as when the proxy was serialized.
  2. Avoid serializing Spring AOP proxies across version boundaries; reconstruct the proxy locally instead.
  3. If a method was legitimately renamed, re-serialize the proxy with the updated class on the producing side.
Defensive patterns

Strategy: try-catch

Validate before calling

// Before deserializing, verify the advice method still exists.
import java.lang.reflect.Method;

boolean adviceMethodExists(Class<?> aspectClass, String methodName, Class<?>[] paramTypes) {
  try { aspectClass.getMethod(methodName, paramTypes); return true; }
  catch (NoSuchMethodException e) { return false; }
}

Try / catch

try {
  Object proxy = objectInputStream.readObject();
} catch (IllegalStateException ex) {
  if (ex.getMessage().equals("Failed to find advice method on deserialization")) {
    log.error("Aspect advice method renamed/removed since serialization", ex);
    // rebuild proxy locally instead of deserializing
  } else throw ex;
}

Prevention

When it happens

Trigger: Deserializing a serialized AOP proxy (or an advisor chain containing an InstantiationModelAwarePointcutAdvisorImpl) on a JVM/classpath where the aspect class's advice method was renamed, removed, or had its parameter list changed.

Common situations: Distributing a serialized Spring AOP proxy across services with different versions of the aspect class. Hot-reloading or upgrading the application between serializing and deserializing a proxy. Refactoring advice method signatures.

Related errors


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