{"record":{"id":"09f5acc1dd529323","repo":"flowable/flowable-engine","slug":"error-writing-dmn-xml","errorCode":null,"errorMessage":"Error writing DMN XML","messagePattern":"Error writing DMN XML","errorType":"exception","errorClass":"DmnXMLException","httpStatus":null,"severity":"error","filePath":"modules/flowable-dmn-xml-converter/src/main/java/org/flowable/dmn/xml/converter/DmnXMLConverter.java","lineNumber":714,"sourceCode":"            }\n\n            DMNDIExport.writeDMNDI(model, xtw);\n\n            // end definitions root element\n            xtw.writeEndElement();\n            xtw.writeEndDocument();\n\n            xtw.flush();\n\n            outputStream.close();\n\n            xtw.close();\n\n            return outputStream.toByteArray();\n\n        } catch (Exception e) {\n            LOGGER.error(\"Error writing DMN XML\", e);\n            throw new DmnXMLException(\"Error writing DMN XML\", e);\n        }\n    }\n\n    protected void writeItemDefinition(List<ItemDefinition> itemDefinitions, DmnDefinition model, XMLStreamWriter xtw) throws Exception {\n        writeItemDefinition(itemDefinitions, false, model, xtw);\n    }\n\n    protected void writeItemDefinition(List<ItemDefinition> itemDefinitions, boolean isItemComponent, DmnDefinition model, XMLStreamWriter xtw) throws Exception {\n        if (itemDefinitions == null) {\n            return;\n        }\n\n        for (ItemDefinition itemDefinition : itemDefinitions) {\n            if (isItemComponent) {\n                xtw.writeStartElement(ELEMENT_ITEM_COMPONENT);\n            } else {\n                xtw.writeStartElement(ELEMENT_ITEM_DEFINITION);\n            }","sourceCodeStart":696,"sourceCodeEnd":732,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-dmn-xml-converter/src/main/java/org/flowable/dmn/xml/converter/DmnXMLConverter.java#L696-L732","documentation":"DmnXMLConverter.convertToXML wraps any Exception thrown while serializing a DmnDefinition back to DMN XML bytes into DmnXMLException(\"Error writing DMN XML\"). This indicates the model could not be written out to the output stream (writer failure, null/invalid model content, or XMLStreamWriter error).","triggerScenarios":"Calling convertToXML(DmnDefinition) when the XMLStreamWriter (e.g. writeStartElement, writeAttribute) throws — typically due to an incomplete or null DmnDefinition, illegal XML characters in values, or an underlying output-stream failure.","commonSituations":"Programmatically constructed DmnDefinition objects missing required fields, strings containing characters illegal in XML, or ByteArrayOutputStream/transformer failures when converting a model between DMN and XML representations in tests or deployments.","solutions":["Inspect the logged stack trace to see which write* call failed","Validate the DmnDefinition: ensure required elements (decisions, rules, expressions) are non-null and populated","Sanitize string values in the model to remove illegal XML control characters","Serialize the model through the Flowable DMN model API (DmnJsonConverter/model builders) instead of hand-building it"],"exampleFix":"// before\nDmnDefinition model = new DmnDefinition(); // partially populated\nbyte[] xml = converter.convertToXML(model);\n// after\nDmnDefinition model = builder.withDecisions(populatedDecisions).build();\nObjects.requireNonNull(model.getDecisions(), \"decisions required\");\nbyte[] xml = converter.convertToXML(model);","handlingStrategy":"validation","validationCode":"// validate model before serializing\nif (model == null || model.getDecisions() == null || model.getDecisions().isEmpty()) {\n    throw new IllegalStateException(\"DmnDefinition has no decisions; cannot serialize\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    byte[] xml = converter.convertToXML(model);\n} catch (DmnXMLException e) {\n    LOGGER.error(\"DMN serialization failed: {}\", e.getCause(), e);\n    throw e;\n}","preventionTips":["Build DmnDefinition objects via the Flowable model APIs rather than hand-construction","Sanitize all string values for illegal XML control characters before adding them to the model","Round-trip test: convertToXML(convertToDmnModel(sample)) in unit tests","Ensure nulls are replaced with defaults before serialization"],"tags":["xml","dmn","serialization","java"],"backgroundTag":"file-write-failed","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}