{"record":{"id":"3f1e628be90a13bc","repo":"spring-projects/spring-security","slug":"unable-to-resolve-builder-for-3f1e62","errorCode":null,"errorMessage":"Unable to resolve Builder for ","messagePattern":"Unable to resolve Builder for ","errorType":"exception","errorClass":"Saml2Exception","httpStatus":null,"severity":"error","filePath":"saml2/saml2-service-provider/src/opensaml5Main/java/org/springframework/security/saml2/provider/service/registration/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/registration/OpenSaml5Template.java#L114-L150","documentation":"OpenSaml5Template.build() looks up an OpenSAML XMLObjectBuilder for the given QName via the global XMLObjectProviderRegistry. When no builder is registered for that element name, the template cannot construct the XMLObject and throws this Saml2Exception. This almost always means the OpenSAML object provider initialization did not run or the element is not a known SAML element.","triggerScenarios":"Calling OpenSaml5Template.build(QName) with a QName whose builder is absent from XMLObjectProviderRegistrySupport — e.g. a typo'd namespace URI or localPart, or building before OpenSAML's InitializationService has registered the standard SAML providers (typically done by OpenSamlInitializationService in this library).","commonSituations":"Using a custom/unknown element QName; constructing the template manually without triggering OpenSAML bootstrap initialization (no class from opensaml-saml-api touched first); mixing OpenSAML 4/5 jars so registry registration fails; building extension elements from a profile whose providers were never registered.","solutions":["Ensure OpenSAML is initialized before building — add opensaml-saml-api/impl to the classpath and let org.springframework.security.saml2 (OpenSamlInitializationService / InitializationService) register the default providers, or call InitializationService.initialize() yourself","Verify the QName's namespace URI and localPart exactly match the SAML element (e.g. Response.DEFAULT_ELEMENT_NAME), not a hand-typed string","Check for conflicting opensaml jar versions on the classpath that may break provider registration","If building a custom element, register an XMLObjectBuilder for it with the BuilderRegistry before calling build"],"exampleFix":"// before\nXMLObject obj = template.build(new QName(\"urn:oasis:names:tc:SAML:2.0:protocol\", \"Resposne\"));\n// after\nXMLObject obj = template.build(Response.DEFAULT_ELEMENT_NAME);","handlingStrategy":"validation","validationCode":"InitializationService.initialize(); // once at startup, before any build()\nif (XMLObjectProviderRegistrySupport.getBuilderFactory().getBuilder(elementName) == null) {\n    throw new IllegalStateException(\"No OpenSAML builder for \" + elementName);\n}","typeGuard":"boolean canBuild(QName name) {\n    return XMLObjectProviderRegistrySupport.getBuilderFactory().getBuilder(name) != null;\n}","tryCatchPattern":"try {\n    T obj = template.build(elementName);\n} catch (Saml2Exception ex) {\n    throw new IllegalStateException(\"Unknown/unregistered element: \" + elementName, ex);\n}","preventionTips":["Call OpenSamlInitializationService.initialize() (or InitializationService.initialize()) at application startup","Use the *DEFAULT_ELEMENT_NAME constants instead of hand-written QNames","Keep a single consistent OpenSAML 5 version on the classpath"],"tags":["saml2","opensaml","initialization","builder-not-found"],"backgroundTag":"resource-not-found","analyzedSha":"96852e8860138a482cb13d1479573f24ff6443c6","analyzedAt":"2026-09-10T23:25:23.477Z","contentChangedAt":"2026-09-10T23:25:23.477Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}