{"record":{"id":"66d6ea6d7f6c5f49","repo":"spring-projects/spring-security","slug":"unable-to-resolve-builder-for-elementname-66d6ea","errorCode":null,"errorMessage":"Unable to resolve Builder for \" + elementName","messagePattern":"Unable to resolve Builder for \" \\+ elementName","errorType":"exception","errorClass":"Saml2Exception","httpStatus":null,"severity":"error","filePath":"saml2/saml2-service-provider/src/opensaml5Main/java/org/springframework/security/saml2/provider/service/authentication/logout/OpenSaml5Template.java","lineNumber":132,"sourceCode":"import org.springframework.security.saml2.core.Saml2ParameterNames;\nimport org.springframework.security.saml2.core.Saml2X509Credential;\nimport org.springframework.util.Assert;\nimport org.springframework.web.util.UriComponentsBuilder;\nimport org.springframework.web.util.UriUtils;\n\n/**\n * For internal use only. Subject to breaking changes at any time.\n */\n@NullMarked\nfinal class OpenSaml5Template implements OpenSamlOperations {\n\n\tprivate static final Log logger = LogFactory.getLog(OpenSaml5Template.class);\n\n\t@Override\n\tpublic <T extends XMLObject> T build(QName elementName) {\n\t\tXMLObjectBuilder<?> builder = XMLObjectProviderRegistrySupport.getBuilderFactory().getBuilder(elementName);\n\t\tif (builder == null) {\n\t\t\tthrow new Saml2Exception(\"Unable to resolve Builder for \" + elementName);\n\t\t}\n\t\treturn (T) builder.buildObject(elementName);\n\t}\n\n\t@Override\n\tpublic <T extends XMLObject> T deserialize(String serialized) {\n\t\treturn deserialize(new ByteArrayInputStream(serialized.getBytes(StandardCharsets.UTF_8)));\n\t}\n\n\t@Override\n\tpublic <T extends XMLObject> T deserialize(InputStream serialized) {\n\t\ttry {\n\t\t\tParserPool pool = XMLObjectProviderRegistrySupport.getParserPool();\n\t\t\tAssert.notNull(pool, \"ParserPool must be configured\");\n\t\t\tDocument document = pool.parse(serialized);\n\t\t\tElement element = document.getDocumentElement();\n\t\t\tUnmarshallerFactory factory = XMLObjectProviderRegistrySupport.getUnmarshallerFactory();\n\t\t\tUnmarshaller unmarshaller = factory.getUnmarshaller(element);","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/spring-projects/spring-security/blob/96852e8860138a482cb13d1479573f24ff6443c6/saml2/saml2-service-provider/src/opensaml5Main/java/org/springframework/security/saml2/provider/service/authentication/logout/OpenSaml5Template.java#L114-L150","documentation":"OpenSaml5Template.build() asks OpenSAML's global XMLObjectProviderRegistry for a builder registered under the given QName and throws this Saml2Exception when none is registered. It means OpenSAML has no provider that can construct XML objects for that element name — typically because OpenSAML initialization (which registers the default providers) did not run, or the element belongs to a module/namespace that is not registered.","triggerScenarios":"Calling OpenSaml5Template.build(QName) with a QName whose element type has no registered XMLObjectBuilder — building a SAML element before OpenSamlInitializationService.initialize() ran, a hand-built QName with a wrong namespace URI or local part, or a custom extension element whose provider was never registered.","commonSituations":"Using OpenSaml5Template in a plain Spring context where the OpenSAML bootstrap never runs; requesting elements from SAML profiles or extensions whose opensaml module dependency is absent; constructing QName literals with a typo'd namespace; upgrading Spring Security/OpenSAML and referencing moved elements.","solutions":["Ensure OpenSAML default providers are initialized before building (call OpenSamlInitializationService.initialize() or let Spring Security's bootstrap run).","Verify the QName namespace URI and local part exactly match a registered SAML element (prefer the element's DEFAULT_ELEMENT_NAME constant).","Add the OpenSAML module that provides the element (opensaml-saml-api/impl for profile elements, opensaml-messaging-api for core objects).","For custom elements, register a builder via XMLObjectProviderRegistry.registerObjectProvider(...)."],"exampleFix":"// before\ntemplate.build(new QName(\"urn:oasis:names:tc:SAML:2.0:assertion\", \"Response\")); // providers not initialized -> Saml2Exception\n// after\nOpenSamlInitializationService.initialize();\nXMLObject response = template.build(Response.DEFAULT_ELEMENT_NAME);","handlingStrategy":"try-catch","validationCode":"OpenSamlInitializationService.initialize();\nif (XMLObjectProviderRegistrySupport.getBuilderFactory().getBuilder(elementName) == null) {\n    throw new IllegalStateException(\"No OpenSAML builder registered for \" + elementName);\n}","typeGuard":"static boolean hasBuilder(QName elementName) {\n    return XMLObjectProviderRegistrySupport.getBuilderFactory().getBuilder(elementName) != null;\n}","tryCatchPattern":"try {\n    T obj = template.build(elementName);\n} catch (Saml2Exception ex) {\n    throw new IllegalStateException(\"OpenSAML builder missing for \" + elementName\n            + \"; ensure OpenSamlInitializationService.initialize() ran and required modules are on the classpath\", ex);\n}","preventionTips":["Call OpenSamlInitializationService.initialize() once at startup before any OpenSAML usage.","Prefer DEFAULT_ELEMENT_NAME constants over hand-built QName literals.","Declare opensaml-saml-api/impl dependencies for every SAML profile element you build.","Check hasBuilder(elementName) in startup health checks for custom elements."],"tags":["saml2","opensaml","builder-not-found","xml-object"],"backgroundTag":"unsupported-operation","analyzedSha":"96852e8860138a482cb13d1479573f24ff6443c6","analyzedAt":"2026-09-10T23:25:23.477Z","contentChangedAt":"2026-09-10T23:25:23.477Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}