{"record":{"id":"90d0cf3f07005a41","repo":"spring-projects/spring-security","slug":"could-not-postprocess-object-of-type-type","errorCode":null,"errorMessage":"Could not postProcess {object} of type {type}","messagePattern":"Could not postProcess (.+?) of type (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"config/src/main/java/org/springframework/security/config/annotation/configuration/AutowireBeanFactoryObjectPostProcessor.java","lineNumber":71,"sourceCode":"\tprivate final List<SmartInitializingSingleton> smartSingletons = new ArrayList<>();\n\n\tAutowireBeanFactoryObjectPostProcessor(AutowireCapableBeanFactory autowireBeanFactory) {\n\t\tAssert.notNull(autowireBeanFactory, \"autowireBeanFactory cannot be null\");\n\t\tthis.autowireBeanFactory = autowireBeanFactory;\n\t}\n\n\t@Override\n\tpublic <T> T postProcess(T object) {\n\t\tif (object == null) {\n\t\t\treturn null;\n\t\t}\n\t\tT result = null;\n\t\ttry {\n\t\t\tresult = initializeBeanIfNeeded(object);\n\t\t}\n\t\tcatch (RuntimeException ex) {\n\t\t\tClass<?> type = object.getClass();\n\t\t\tthrow new RuntimeException(\"Could not postProcess \" + object + \" of type \" + type, ex);\n\t\t}\n\t\tthis.autowireBeanFactory.autowireBean(object);\n\t\tif (result instanceof DisposableBean) {\n\t\t\tthis.disposableBeans.add((DisposableBean) result);\n\t\t}\n\t\tif (result instanceof SmartInitializingSingleton) {\n\t\t\tthis.smartSingletons.add((SmartInitializingSingleton) result);\n\t\t}\n\t\treturn result;\n\t}\n\n\t/**\n\t * Invokes {@link AutowireCapableBeanFactory#initializeBean(Object, String)} only if\n\t * needed, i.e when the application is not a native image or the object is not a CGLIB\n\t * proxy.\n\t * @param object the object to initialize\n\t * @param <T> the type of the object\n\t * @return the initialized bean or an existing bean if the object is a CGLIB proxy and","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/spring-projects/spring-security/blob/96852e8860138a482cb13d1479573f24ff6443c6/config/src/main/java/org/springframework/security/config/annotation/configuration/AutowireBeanFactoryObjectPostProcessor.java#L53-L89","documentation":"AutowireBeanFactoryObjectPostProcessor.postProcess initializes and autowires arbitrary objects against the BeanFactory; if initializeBeanIfNeeded throws a RuntimeException, it wraps it in a RuntimeException('Could not postProcess <object> of type <type>') preserving the cause. It signals that Spring could not lifecycle-initialize an object created by a security configurer.","triggerScenarios":"Any object passed through ObjectPostProcessor whose init()/afterPropertiesSet() or bean initialization throws — e.g. an embedded LDAP server failing to start, a filter bean with bad configuration — during security configuration building.","commonSituations":"Embedded LDAP port already in use or missing LDIF; misconfigured servlet filters passed via addFilter with postProcess; beans requiring dependencies unavailable at that lifecycle stage; native-image/GraalVM environments where reflective init fails.","solutions":["Inspect the cause chain (ex.getCause()) of the thrown RuntimeException for the real initialization failure.","Fix the underlying object's configuration (port conflicts, missing resources, invalid properties).","Ensure required classes/dependencies exist at runtime, especially for embedded servers (unboundid-ldapsdk) and native images (registration/hints).","If the object does not need bean initialization, avoid wrapping it with objectPostProcessor or use a plain constructor."],"exampleFix":"// before\nLdapBindAuthenticationManagerFactory f = new LdapBindAuthenticationManagerFactory(contextSource); // init failed, cause hidden\n// after\ncatch (RuntimeException e) {\n    log.error(\"postProcess failed: {}\", e.getCause(), e.getCause()); // find the real init error first\n}\n// then fix the underlying config, e.g. free the LDAP port or fix the LDIF path","handlingStrategy":"try-catch","validationCode":"// validate object config before post-processing\nif (object instanceof UnboundIdContainer c && c.getPort() == 0) {\n    throw new IllegalArgumentException(\"embedded LDAP port must be set\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    processed = objectPostProcessor.postProcess(object);\n} catch (RuntimeException e) {\n    // 'Could not postProcess ... of type ...' always wraps the real cause\n    log.error(\"Post-process failed for {}: {}\", e.getMessage(), e.getCause(), e.getCause());\n    throw e;\n}","preventionTips":["Always inspect getCause() — this wrapper hides the real failure","Validate ports, LDIF paths, and filter configuration before build","Add required dependencies (e.g. unboundid-ldapsdk) to the runtime classpath","Provide GraalVM RuntimeHints if running in native image"],"tags":["objectpostprocessor","spring-beans","initialization","configuration"],"backgroundTag":"module-init-failed","analyzedSha":"96852e8860138a482cb13d1479573f24ff6443c6","analyzedAt":"2026-09-10T23:25:23.477Z","contentChangedAt":"2026-09-10T23:25:23.477Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}