flowable/flowable-engine · error · DmnXMLException
Error writing DMN XML
Error message
Error writing DMN XML
What it means
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).
Source
Thrown at modules/flowable-dmn-xml-converter/src/main/java/org/flowable/dmn/xml/converter/DmnXMLConverter.java:714
}
DMNDIExport.writeDMNDI(model, xtw);
// end definitions root element
xtw.writeEndElement();
xtw.writeEndDocument();
xtw.flush();
outputStream.close();
xtw.close();
return outputStream.toByteArray();
} catch (Exception e) {
LOGGER.error("Error writing DMN XML", e);
throw new DmnXMLException("Error writing DMN XML", e);
}
}
protected void writeItemDefinition(List<ItemDefinition> itemDefinitions, DmnDefinition model, XMLStreamWriter xtw) throws Exception {
writeItemDefinition(itemDefinitions, false, model, xtw);
}
protected void writeItemDefinition(List<ItemDefinition> itemDefinitions, boolean isItemComponent, DmnDefinition model, XMLStreamWriter xtw) throws Exception {
if (itemDefinitions == null) {
return;
}
for (ItemDefinition itemDefinition : itemDefinitions) {
if (isItemComponent) {
xtw.writeStartElement(ELEMENT_ITEM_COMPONENT);
} else {
xtw.writeStartElement(ELEMENT_ITEM_DEFINITION);
}View on GitHub (pinned to d6d39ce1c6)
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
Example fix
// before DmnDefinition model = new DmnDefinition(); // partially populated byte[] xml = converter.convertToXML(model); // after DmnDefinition model = builder.withDecisions(populatedDecisions).build(); Objects.requireNonNull(model.getDecisions(), "decisions required"); byte[] xml = converter.convertToXML(model);
Defensive patterns
Strategy: validation
Validate before calling
// validate model before serializing
if (model == null || model.getDecisions() == null || model.getDecisions().isEmpty()) {
throw new IllegalStateException("DmnDefinition has no decisions; cannot serialize");
} Try / catch
try {
byte[] xml = converter.convertToXML(model);
} catch (DmnXMLException e) {
LOGGER.error("DMN serialization failed: {}", e.getCause(), e);
throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.
Related errors
- Error writing BPMN XML
- Error writing CMMN XML
- The bpmn 2.0 xml is not properly encoded
- Error while reading the BPMN 2.0 XML
- e.getMessage()
AI-assisted analysis of flowable/flowable-engine@d6d39ce1c6 (2026-09-11).
Data as JSON: /api/errors/09f5acc1dd529323.
Report an issue: GitHub.