{"record":{"id":"831e2d8b8a203585","repo":"flowable/flowable-engine","slug":"can-t-clear-configuration-beans","errorCode":null,"errorMessage":"can't clear configuration beans","messagePattern":"can't clear configuration beans","errorType":"exception","errorClass":"org.flowable.common.engine.api.FlowableException","httpStatus":null,"severity":"error","filePath":"modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/cfg/SpringBeanFactoryProxyMap.java","lineNumber":60,"sourceCode":"    @Override\n    public boolean containsKey(Object key) {\n        if ((key == null) || !String.class.isAssignableFrom(key.getClass())) {\n            return false;\n        }\n        return beanFactory.containsBean((String) key);\n    }\n\n    @Override\n    public Set<Object> keySet() {\n        throw new FlowableException(\"unsupported operation on configuration beans\");\n        // List<String> beanNames =\n        // Arrays.asList(beanFactory.getBeanDefinitionNames());\n        // return new HashSet<Object>(beanNames);\n    }\n\n    @Override\n    public void clear() {\n        throw new FlowableException(\"can't clear configuration beans\");\n    }\n\n    @Override\n    public boolean containsValue(Object value) {\n        throw new FlowableException(\"can't search values in configuration beans\");\n    }\n\n    @Override\n    public Set<Map.Entry<Object, Object>> entrySet() {\n        throw new FlowableException(\"unsupported operation on configuration beans\");\n    }\n\n    @Override\n    public boolean isEmpty() {\n        throw new FlowableException(\"unsupported operation on configuration beans\");\n    }\n\n    @Override","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/cfg/SpringBeanFactoryProxyMap.java#L42-L78","documentation":"clear() is unsupported on SpringBeanFactoryProxyMap because the map is a live view over the Spring BeanFactory; beans are managed by Spring and cannot be removed through this facade. The method throws unconditionally.","triggerScenarios":"Calling clear() directly on the map, or indirectly via Map.clear() invoked by framework cleanup code (e.g. context shutdown helpers, cache eviction, or code treating the map as a mutable cache).","commonSituations":"Code that clears shared configuration maps on restart/reload, generic map-reset logic in tests, or libraries that accept a Map and clear it before repopulating.","solutions":["Do not call clear() on this map; it is backed by the Spring context and cleared by closing the ApplicationContext","Remove only application-level beans via Spring lifecycle (destroy beans or refresh the context), not via this Map API","If mutable behavior is required, wrap or replace the map with a plain HashMap populated with the beans you control"],"exampleFix":"// before\nconfigBeans.clear();\n// after\n// let Spring manage lifecycle:\napplicationContext.close(); // or context.refresh()","handlingStrategy":"type-guard","validationCode":"if (map instanceof SpringBeanFactoryProxyMap) {\n    throw new IllegalStateException(\"use ApplicationContext lifecycle to clear beans\");\n}","typeGuard":"boolean isMutableMap(Map<?,?> m) { return !(m instanceof SpringBeanFactoryProxyMap); }","tryCatchPattern":"try {\n    map.clear();\n} catch (FlowableException e) {\n    // fall back to Spring lifecycle\n    applicationContext.close();\n}","preventionTips":["Never treat the bean map as a mutable cache","Let Spring own bean lifecycle (close/refresh the context)","If mutation is needed, use a real Map such as ProcessEngineConfiguration.getBeans()"],"tags":["spring","map","unsupported-operation","flowable"],"backgroundTag":"unsupported-operation","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}