spring-projects/spring-framework · error · AopConfigException
Cannot remove Advisor: Configuration is frozen.
Error message
Cannot remove Advisor: Configuration is frozen.
What it means
AdvisedSupport.removeAdvisor(int) (line 328) refuses to mutate its advisor list when the configuration is frozen (isFrozen() true, line 329). A frozen Advised is immutable - typically because the proxy has been built and optimized, or setFrozen(true) was explicitly called. Removal would break cached interceptor chains.
Solutions
- Do not call setFrozen(true) if you need to mutate the advisor chain at runtime
- If the proxy is already created and frozen, rebuild a new ProxyFactory from the configuration instead of mutating in place
- Check ((Advised) proxy).isFrozen() before attempting removal and handle accordingly
Example fix
// before AdvisedSupport advised = ...; advised.setFrozen(true); advised.removeAdvisor(0); // after AdvisedSupport advised = ...; advised.setFrozen(false); advised.removeAdvisor(0);
Defensive patterns
Strategy: validation
Validate before calling
if (advised.isFrozen()) {
throw new IllegalStateException("Cannot remove advisor: configuration is frozen");
}
advised.removeAdvisor(index); Type guard
private static boolean canRemoveAdvisor(AdvisedSupport a) {
return a != null && !a.isFrozen();
} Prevention
- Do not setFrozen(true) if you need to mutate advisors at runtime
- Always check isFrozen() before removeAdvisor calls on user-facing APIs
When it happens
Trigger: Calling removeAdvisor(index) or removeAdvisor(advisor) (which delegates to removeAdvisor(index)) on an Advised/AdvisedSupport whose frozen flag is set.
Common situations: Manually calling setFrozen(true) for optimization then trying to mutate; holding a reference to an Advised proxy and attempting runtime advisor removal after the proxy was created with optimization/frozen; AdvisedSupport snapshots used internally by already-built proxies.
Related errors
- Cannot add advisor: Configuration is frozen.
- Advisor index is out of bounds: This configuration only has…
- DynamicIntroductionAdvice may only be added as part of…
- Illegal position in advisor list with size
- Cannot get bean name; not set on MethodInvocation
AI-assisted analysis of spring-projects/spring-framework@69bf83ad71 (2026-08-09).
Data as JSON: /api/errors/30559adceb3d4a0a.
Report an issue: GitHub.
Appendix: source
Thrown at spring-aop/src/main/java/org/springframework/aop/framework/AdvisedSupport.java:330
addAdvisorInternal(pos, advisor);
}
@Override
public boolean removeAdvisor(Advisor advisor) {
int index = indexOf(advisor);
if (index == -1) {
return false;
}
else {
removeAdvisor(index);
return true;
}
}
@Override
public void removeAdvisor(int index) throws AopConfigException {
if (isFrozen()) {
throw new AopConfigException("Cannot remove Advisor: Configuration is frozen.");
}
if (index < 0 || index > this.advisors.size() - 1) {
throw new AopConfigException("Advisor index " + index + " is out of bounds: " +
"This configuration only has " + this.advisors.size() + " advisors.");
}
Advisor advisor = this.advisors.remove(index);
if (advisor instanceof IntroductionAdvisor introductionAdvisor) {
// We need to remove introduction interfaces.
for (Class<?> ifc : introductionAdvisor.getInterfaces()) {
removeInterface(ifc);
}
}
adviceChanged();
}
@OverrideView on GitHub (pinned to 69bf83ad71)