spring-projects/spring-framework · error · AopConfigException
Advisor index {} is out of bounds: This configuration only h
Error message
Advisor index {} is out of bounds: This configuration only has {} advisors. What it means
removeAdvisor(int index) (line 332) validates the index against the advisor list size. It throws when index is negative or greater than size-1, telling you exactly how many advisors exist. This runs after the frozen check, so it only matters on a non-frozen configuration.
Source
Thrown at spring-aop/src/main/java/org/springframework/aop/framework/AdvisedSupport.java:333
@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();
}
@Override
public int indexOf(Advisor advisor) {
Assert.notNull(advisor, "Advisor must not be null");
return this.advisors.indexOf(advisor);View on GitHub (pinned to 69bf83ad71)
Solutions
- Guard with: int i = advised.indexOf(a); if (i >= 0) advised.removeAdvisor(i);
- Call getAdvisorCount()/getAdvisors().length first and bounds-check your index
- Prefer removeAdvisor(advisor) over manual index arithmetic, then check its boolean return
Example fix
// before
int i = advised.indexOf(someAdvisor); // could be -1
advised.removeAdvisor(i);
// after
if (!advised.removeAdvisor(someAdvisor)) {
// advisor was not present; handle gracefully
} Defensive patterns
Strategy: validation
Validate before calling
int count = advised.getAdvisorCount();
if (index < 0 || index > count - 1) {
throw new IndexOutOfBoundsException("advisor index " + index + " out of bounds (size " + count + ")");
}
advised.removeAdvisor(index); Type guard
private static boolean validAdvisorIndex(AdvisedSupport a, int i) {
return a != null && i >= 0 && i < a.getAdvisorCount();
} Prevention
- Prefer removeAdvisor(advisor) and check its boolean result over index arithmetic
- Always recompute the index from getAdvisorCount() immediately before removal
When it happens
Trigger: Calling removeAdvisor with an index < 0 or >= advisors.size(); computing an index dynamically (e.g. via indexOf returning -1 and not checking) and passing it through.
Common situations: Using indexOf(advisor) which returned -1 (not found) and blindly passing it to removeAdvisor; stale index from a previous snapshot; off-by-one when iterating.
Related errors
- Illegal position {} in advisor list with size {}
- Cannot remove Advisor: Configuration is frozen.
- Cannot add advisor: Configuration is frozen.
- DynamicIntroductionAdvice may only be added as part of Intro
- [{ifc.getName()}] is not an interface
AI-assisted analysis of spring-projects/spring-framework@69bf83ad71 (2026-08-09).
Data as JSON: /api/errors/e2d5436eab8e2ab3.
Report an issue: GitHub.