{"record":{"id":"ba0c9f83bd75c3ed","repo":"spring-projects/spring-framework","slug":"mapped-value","errorCode":null,"errorMessage":"Mapped value [","messagePattern":"Mapped value \\[","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-beans/src/main/java/org/springframework/beans/factory/config/CustomScopeConfigurer.java","lineNumber":113,"sourceCode":"\n\t@Override\n\tpublic void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {\n\t\tif (this.scopes != null) {\n\t\t\tthis.scopes.forEach((scopeKey, value) -> {\n\t\t\t\tif (value instanceof Scope scope) {\n\t\t\t\t\tbeanFactory.registerScope(scopeKey, scope);\n\t\t\t\t}\n\t\t\t\telse if (value instanceof Class<?> scopeClass) {\n\t\t\t\t\tAssert.isAssignable(Scope.class, scopeClass, \"Invalid scope class\");\n\t\t\t\t\tbeanFactory.registerScope(scopeKey, (Scope) BeanUtils.instantiateClass(scopeClass));\n\t\t\t\t}\n\t\t\t\telse if (value instanceof String scopeClassName) {\n\t\t\t\t\tClass<?> scopeClass = ClassUtils.resolveClassName(scopeClassName, this.beanClassLoader);\n\t\t\t\t\tAssert.isAssignable(Scope.class, scopeClass, \"Invalid scope class\");\n\t\t\t\t\tbeanFactory.registerScope(scopeKey, (Scope) BeanUtils.instantiateClass(scopeClass));\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tthrow new IllegalArgumentException(\"Mapped value [\" + value + \"] for scope key [\" +\n\t\t\t\t\t\t\tscopeKey + \"] is not an instance of required type [\" + Scope.class.getName() +\n\t\t\t\t\t\t\t\"] or a corresponding Class or String value indicating a Scope implementation\");\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t}\n\n}\n","sourceCodeStart":95,"sourceCodeEnd":122,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/69bf83ad716d0cfc4b0520a19b4d8b24c79d1538/spring-beans/src/main/java/org/springframework/beans/factory/config/CustomScopeConfigurer.java#L95-L122","documentation":"Thrown as an IllegalArgumentException by CustomScopeConfigurer.postProcessBeanFactory when a value in its scopes map is not an instance of Scope, a Class assignable to Scope, or a String naming a Scope class. The configurer (a BeanFactoryPostProcessor) registers custom scopes from a map keyed by scope name; any other value type is rejected with the offending value and key in the message.","triggerScenarios":"Setting CustomScopeConfigurer.setScopes(map) with a map entry whose value is an Integer, a non-Scope bean, a Class that is not assignable to Scope, or a String that resolves to a non-Scope class. postProcessBeanFactory iterates the map and throws on the first unsupported value type.","commonSituations":"XML <bean class='...CustomScopeConfigurer'> with a <map> entry whose value-ref points at a non-Scope bean; @Bean method building the scopes map with the wrong value; passing a scope name as value instead of the Scope instance; typo in the scope class FQN string; reflective bean copy that loses type info.","solutions":["Ensure each scope map value is a Scope instance, a Class<? extends Scope>, or a String holding the FQN of a Scope implementation.","Point the map value at the actual Scope bean (e.g. SimpleThreadScope, RequestScope) rather than a scope name or unrelated bean.","If using XML, fix the <entry> so value-ref points at the Scope bean, or use key='scopeName' value='fqcn'.","Register the scope programmatically with beanFactory.registerScope(name, scopeInstance) to bypass the map entirely.","Add an assertion in test code that every map value is assignable to Scope before calling setScopes."],"exampleFix":"<!-- before: value is a scope name String, not a Scope -->\n<bean class='o.s.beans.factory.config.CustomScopeConfigurer'>\n  <property name='scopes'>\n    <map><entry key='thread' value='thread'/></map>\n  </property>\n</bean>\n\n<!-- after: value is a Scope bean reference -->\n<bean class='o.s.beans.factory.config.CustomScopeConfigurer'>\n  <property name='scopes'>\n    <map>\n      <entry key='thread' value-ref='threadScope'/>\n    </map>\n  </property>\n</bean>\n<bean id='threadScope' class='o.s.context.support.SimpleThreadScope'/>","handlingStrategy":"validation","validationCode":"Map<String, ?> scopes = customScopeConfigurer.getScopes();\nscopes.forEach((k, v) -> {\n    boolean ok = v instanceof Scope || v instanceof Class<?> c && Scope.class.isAssignableFrom(c)\n        || v instanceof String;\n    if (!ok) throw new IllegalArgumentException(\"Invalid scope value for key \" + k + \": \" + v);\n});","typeGuard":"boolean isValidScopeValue(Object v) {\n    return v instanceof Scope ||\n        (v instanceof Class<?> c && Scope.class.isAssignableFrom(c)) ||\n        v instanceof String;\n}","tryCatchPattern":null,"preventionTips":["Use beanFactory.registerScope(name, scopeInstance) directly to avoid the map.","Point CustomScopeConfigurer map values at Scope bean references, not names.","Lint XML scope-config entries for value-ref correctness.","Add a config sanity test that asserts each scope value is a Scope/Class/String."],"tags":["spring","scopes","configuration","bean-factory-post-processor"],"backgroundTag":null,"analyzedSha":"69bf83ad716d0cfc4b0520a19b4d8b24c79d1538","analyzedAt":"2026-08-09T15:32:58.770Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}