{"record":{"id":"b750a23b3335a159","repo":"OpenFeign/feign","slug":"jaxbcontextfactory-must-be-non-null-b750a2","errorCode":null,"errorMessage":"JAXBContextFactory must be non-null","messagePattern":"JAXBContextFactory must be non-null","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"soap-jakarta/src/main/java/feign/soap/SOAPEncoder.java","lineNumber":220,"sourceCode":"    }\n\n    /**\n     * The protocol used to create message factory. Default is \"SOAP 1.1 Protocol\".\n     *\n     * @param soapProtocol a string constant representing the MessageFactory protocol.\n     * @see SOAPConstants#SOAP_1_1_PROTOCOL\n     * @see SOAPConstants#SOAP_1_2_PROTOCOL\n     * @see SOAPConstants#DYNAMIC_SOAP_PROTOCOL\n     * @see MessageFactory#newInstance(String)\n     */\n    public Builder withSOAPProtocol(String soapProtocol) {\n      this.soapProtocol = soapProtocol;\n      return this;\n    }\n\n    public SOAPEncoder build() {\n      if (jaxbContextFactory == null) {\n        throw new IllegalStateException(\"JAXBContextFactory must be non-null\");\n      }\n      return new SOAPEncoder(this);\n    }\n  }\n\n  @Override\n  public boolean canEncode(Object object, Type bodyType, RequestTemplate template) {\n    return Util.isXmlContentType(template);\n  }\n}\n","sourceCodeStart":202,"sourceCodeEnd":231,"githubUrl":"https://github.com/OpenFeign/feign/blob/e2a1e27560a1e68840c34f031afca88b36096e30/soap-jakarta/src/main/java/feign/soap/SOAPEncoder.java#L202-L231","documentation":"SOAPEncoder.Builder requires a JAXBContextFactory to create Marshallers for serializing request bodies; build() throws IllegalStateException if the factory was never supplied. This fail-fast check prevents a broken encoder from being wired into a Feign client.","triggerScenarios":"Calling new SOAPEncoder.Builder().build() without .withJAXBContextFactory(...) when configuring the soap-jakarta module's encoder.","commonSituations":"Builder chain copied from another encoder config; assuming SOAPEncoder has a default constructor; factory bean not yet initialized in the application context.","solutions":["Add .withJAXBContextFactory(jaxbFactory) to the SOAPEncoder.Builder before build().","Share a single JAXBContextFactory between the encoder and decoder builders.","Verify the factory construction (new JAXBContextFactory.Builder().build()) is executed before the encoder builder runs."],"exampleFix":"// before\nSOAPEncoder encoder = new SOAPEncoder.Builder().build();\n// after\nSOAPEncoder encoder = new SOAPEncoder.Builder()\n    .withJAXBContextFactory(jaxbFactory)\n    .build();","handlingStrategy":"validation","validationCode":"JAXBContextFactory factory = /* shared instance */;\njava.util.Objects.requireNonNull(factory, \"JAXBContextFactory must be created before building SOAPEncoder\");","typeGuard":null,"tryCatchPattern":"try {\n  encoder = new SOAPEncoder.Builder().withJAXBContextFactory(factory).build();\n} catch (IllegalStateException e) {\n  if (\"JAXBContextFactory must be non-null\".equals(e.getMessage())) {\n    throw new IllegalStateException(\"Encoder misconfigured: supply JAXBContextFactory\", e);\n  }\n  throw e;\n}","preventionTips":["Always pair withJAXBContextFactory with SOAPEncoder.Builder.","Share the factory instance with the decoder builder.","Add a startup smoke test that builds encoder and decoder once."],"tags":["soap","jaxb","builder","configuration","null-check"],"backgroundTag":"missing-required-argument","analyzedSha":"e2a1e27560a1e68840c34f031afca88b36096e30","analyzedAt":"2026-09-10T12:37:37.238Z","contentChangedAt":"2026-09-10T12:37:37.238Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}