{"id":"e5088d4d46f4a31f","repo":"spring-projects/spring-framework","slug":"cannot-add-advisor-configuration-is-frozen","errorCode":null,"errorMessage":"Cannot add advisor: Configuration is frozen.","messagePattern":"Cannot add advisor: Configuration is frozen\\.","errorType":"exception","errorClass":"AopConfigException","httpStatus":null,"severity":"error","filePath":"spring-aop/src/main/java/org/springframework/aop/framework/AdvisedSupport.java","lineNumber":381,"sourceCode":"\t\taddAdvisor(index, b);\n\t\treturn true;\n\t}\n\n\t/**\n\t * Add all the given advisors to this proxy configuration.\n\t * @param advisors the advisors to register\n\t */\n\tpublic void addAdvisors(Advisor... advisors) {\n\t\taddAdvisors(Arrays.asList(advisors));\n\t}\n\n\t/**\n\t * Add all the given advisors to this proxy configuration.\n\t * @param advisors the advisors to register\n\t */\n\tpublic void addAdvisors(Collection<Advisor> advisors) {\n\t\tif (isFrozen()) {\n\t\t\tthrow new AopConfigException(\"Cannot add advisor: Configuration is frozen.\");\n\t\t}\n\t\tif (!CollectionUtils.isEmpty(advisors)) {\n\t\t\tfor (Advisor advisor : advisors) {\n\t\t\t\tif (advisor instanceof IntroductionAdvisor introductionAdvisor) {\n\t\t\t\t\tvalidateIntroductionAdvisor(introductionAdvisor);\n\t\t\t\t}\n\t\t\t\tAssert.notNull(advisor, \"Advisor must not be null\");\n\t\t\t\tthis.advisors.add(advisor);\n\t\t\t}\n\t\t\tadviceChanged();\n\t\t}\n\t}\n\n\tprivate void validateIntroductionAdvisor(IntroductionAdvisor advisor) {\n\t\tadvisor.validateInterfaces();\n\t\t// If the advisor passed validation, we can make the change.\n\t\tfor (Class<?> ifc : advisor.getInterfaces()) {\n\t\t\taddInterface(ifc);","sourceCodeStart":363,"sourceCodeEnd":399,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/e8729d043887bf0d0baf91e062e909b56eb2b708/spring-aop/src/main/java/org/springframework/aop/framework/AdvisedSupport.java#L363-L399","documentation":"Thrown by AdvisedSupport.addAdvisors(Collection) when the configuration is frozen (isFrozen()==true). This mirrors the remove-side freeze guard: once frozen, the advisor list is immutable and batch additions are rejected up front before any element is processed. Note this check happens before the empty-collection short-circuit, so even adding zero advisors to a frozen config throws.","triggerScenarios":"Calling advised.addAdvisors(list) on a proxy whose config was frozen; bulk-loading advisors from external config at runtime into a frozen proxy; framework code path that froze the config (e.g. after getProxy with frozen=true) followed by user code calling addAdvisors.","commonSituations":"Building proxies with frozen=true for performance and later trying to extend them; AOT/native scenarios; shared/prototype configuration snapshots that are intentionally immutable.","solutions":["Leave setFrozen(false) (default) if the proxy must accept new advisors at runtime.","Create a new ProxyFactory with the combined advisor set and build a fresh proxy.","If batch addition is conditional, guard with !advised.isFrozen() before calling addAdvisors to avoid the exception entirely."],"exampleFix":"// before\nProxyFactory pf = new ProxyFactory(target);\npf.setFrozen(true);\nObject proxy = pf.getProxy();\n((Advised) proxy).addAdvisors(Arrays.asList(extraAdvisor));  // throws\n\n// after\nProxyFactory pf = new ProxyFactory(target);\n// keep frozen=false\nObject proxy = pf.getProxy();\n((Advised) proxy).addAdvisors(Arrays.asList(extraAdvisor));  // ok","handlingStrategy":"validation","validationCode":"Advised advised = (Advised) proxy;\nif (advised.isFrozen()) {\n  // fall back to building a new proxy instead of mutating\n  ProxyFactory pf = new ProxyFactory();\n  pf.copyFrom((ProxyConfig) advised);\n  for (Advisor a : advised.getAdvisors()) pf.addAdvisor(a);\n  pf.addAdvisors(newAdvisors);\n  return pf.getProxy();\n}\nadvised.addAdvisors(newAdvisors);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep frozen=false (default) on proxies that need runtime advisor additions.","Batch all advisors before getProxy() so runtime mutation isn't required.","Guard bulk-add code with !isFrozen() and a rebuild fallback."],"tags":["spring-aop","frozen-config","advisor-mutation","configuration"],"analyzedSha":"e8729d043887bf0d0baf91e062e909b56eb2b708","analyzedAt":"2026-08-04T19:07:39.725Z","schemaVersion":2}