{"record":{"id":"b8bd5545084a83f0","repo":"OpenFeign/feign","slug":"e-tostring-b8bd55","errorCode":null,"errorMessage":"${e.toString()}","messagePattern":"\\$\\{e\\.toString\\(\\)\\}","errorType":"exception","errorClass":"DecodeException","httpStatus":null,"severity":"error","filePath":"jaxb/src/main/java/feign/jaxb/JAXBDecoder.java","lineNumber":97,"sourceCode":"\n    try {\n      SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();\n      /* Explicitly control sax configuration to prevent XXE attacks */\n      saxParserFactory.setFeature(\"http://xml.org/sax/features/external-general-entities\", false);\n      saxParserFactory.setFeature(\"http://xml.org/sax/features/external-parameter-entities\", false);\n      saxParserFactory.setFeature(\"http://apache.org/xml/features/disallow-doctype-decl\", false);\n      saxParserFactory.setFeature(\n          \"http://apache.org/xml/features/nonvalidating/load-external-dtd\", false);\n      saxParserFactory.setNamespaceAware(namespaceAware);\n\n      return jaxbContextFactory\n          .createUnmarshaller((Class<?>) type)\n          .unmarshal(\n              new SAXSource(\n                  saxParserFactory.newSAXParser().getXMLReader(),\n                  new InputSource(response.body().asInputStream())));\n    } catch (JAXBException | ParserConfigurationException | SAXException e) {\n      throw new DecodeException(response.status(), e.toString(), response.request(), e);\n    } finally {\n      if (response.body() != null) {\n        response.body().close();\n      }\n    }\n  }\n\n  public static class Builder {\n    private boolean namespaceAware = true;\n    private JAXBContextFactory jaxbContextFactory;\n\n    /** Controls whether the underlying XML parser is namespace aware. Default is true. */\n    public Builder withNamespaceAware(boolean namespaceAware) {\n      this.namespaceAware = namespaceAware;\n      return this;\n    }\n\n    public Builder withJAXBContextFactory(JAXBContextFactory jaxbContextFactory) {","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/OpenFeign/feign/blob/e2a1e27560a1e68840c34f031afca88b36096e30/jaxb/src/main/java/feign/jaxb/JAXBDecoder.java#L79-L115","documentation":"Same failure as the jakarta variant: JAXBDecoder catches JAXBException/ParserConfigurationException/SAXException during SAX-based unmarshalling and rethrows them as DecodeException with e.toString(). It indicates the response body could not be parsed or bound to the target JAXB class.","triggerScenarios":"Response body is not well-formed XML, root element/namespaces do not match the expected @XmlRootElement type, or SAX parser/stream failure while decoding.","commonSituations":"HTML error pages from gateways; XML namespace mismatches between response and DTOs; missing @XmlRootElement causing JAXBException; truncated responses.","solutions":["Inspect e.getCause() to distinguish parse failures from binding failures.","Confirm the server returns XML matching the declared return type (root element, namespaces).","Ensure DTOs are JAXB-annotated and registered with the JAXBContextFactory.","Catch DecodeException and handle non-XML (e.g. HTML) error responses."],"exampleFix":"// before\nItem i = api.get();\n// after\ntry { Item i = api.get(); }\ncatch (DecodeException e) { log.warn(\"bad xml: {}\", String.valueOf(e.getCause())); }","handlingStrategy":"try-catch","validationCode":"// before decoding\nif (response.status() >= 400) { /* handle error response before decoding body */ }","typeGuard":null,"tryCatchPattern":"try {\n  result = client.call();\n} catch (DecodeException e) {\n  if (e.getCause() instanceof SAXException) { /* malformed XML */ }\n  else if (e.getCause() instanceof JAXBException) { /* mapping mismatch */ }\n  else { throw e; }\n}","preventionTips":["Check Content-Type and status before decoding XML endpoints.","Keep DTO annotations aligned with the server XML schema, including namespaces.","Add DecodeException handling for gateway/HTML error pages.","Validate payloads against an XSD in integration tests."],"tags":["jaxb","decode","xml-parsing"],"backgroundTag":"xml-unmarshal-failed","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"}