{"record":{"id":"ff38d1d9f8ad5566","repo":"flowable/flowable-engine","slug":"error-while-parsing-bpmn-model","errorCode":null,"errorMessage":"Error while parsing BPMN model.","messagePattern":"Error while parsing BPMN model\\.","errorType":"exception","errorClass":"FlowableException","httpStatus":null,"severity":"error","filePath":"modules/flowable-engine/src/main/java/org/flowable/engine/impl/bpmn/diagram/ProcessDiagramLayoutFactory.java","lineNumber":114,"sourceCode":"        Map<String, DiagramElement> listOfBoundsForImage = transformBoundsForImage(diagramBoundsImage, diagramBoundsXml, listOfBounds);\n        return new DiagramLayout(listOfBoundsForImage);\n    }\n\n    protected Document parseXml(InputStream bpmnXmlStream) {\n        // Initiate DocumentBuilderFactory\n        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();\n        // Get one that understands namespaces\n        factory.setNamespaceAware(true);\n\n        DocumentBuilder builder;\n        Document bpmnModel;\n        try {\n            // Get DocumentBuilder\n            builder = factory.newDocumentBuilder();\n            // Parse and load the Document into memory\n            bpmnModel = builder.parse(bpmnXmlStream);\n        } catch (Exception e) {\n            throw new FlowableException(\"Error while parsing BPMN model.\", e);\n        }\n        return bpmnModel;\n    }\n\n    protected DiagramNode getDiagramBoundsFromBpmnDi(Document bpmnModel) {\n        Double minX = null;\n        Double minY = null;\n        Double maxX = null;\n        Double maxY = null;\n\n        // Node positions and dimensions\n        NodeList setOfBounds = bpmnModel.getElementsByTagNameNS(BpmnParser.BPMN_DC_NS, \"Bounds\");\n        for (int i = 0; i < setOfBounds.getLength(); i++) {\n            Element element = (Element) setOfBounds.item(i);\n            Double x = Double.valueOf(element.getAttribute(\"x\"));\n            Double y = Double.valueOf(element.getAttribute(\"y\"));\n            Double width = Double.valueOf(element.getAttribute(\"width\"));\n            Double height = Double.valueOf(element.getAttribute(\"height\"));","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-engine/src/main/java/org/flowable/engine/impl/bpmn/diagram/ProcessDiagramLayoutFactory.java#L96-L132","documentation":"ProcessDiagramLayoutFactory.parseXml parses the BPMN XML stream into a DOM Document using javax.xml.parsers.DocumentBuilder to extract diagram layout info. Any parse failure (malformed XML, IO error on the stream) is wrapped in this FlowableException.","triggerScenarios":"getBpmnProcessDiagramLayout is given BPMN XML that DocumentBuilder.parse cannot handle: not well-formed XML, wrong encoding, empty/closed stream. Reached via bpmnModel().","commonSituations":"Hand-edited BPMN files with syntax errors; XML with undeclared entities/encoding issues; passing an already-consumed or null InputStream; non-XML content accidentally passed as BPMN XML.","solutions":["Validate the BPMN XML is well-formed (xmllint or an XML editor) before using diagram layout generation","Ensure the InputStream is open, positioned at start, and contains the BPMN XML bytes","Check the XML declaration/encoding matches the actual byte encoding of the stream","Inspect the wrapped cause exception for the exact SAX parser error and line number"],"exampleFix":"// before\nfactory.getProcessDiagramLayout(bpmnXmlStream, imageStream);\n\n// after: validate XML first\ntry (InputStream in = new ByteArrayInputStream(bpmnXml.getBytes(StandardCharsets.UTF_8))) {\n    Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(in); // fails fast with a clear error\n} catch (Exception e) {\n    throw new IllegalArgumentException(\"Invalid BPMN XML: \" + e.getMessage(), e);\n}","handlingStrategy":"validation","validationCode":"DocumentBuilderFactory f = DocumentBuilderFactory.newInstance();\nf.newDocumentBuilder().parse(new ByteArrayInputStream(bpmnXml.getBytes(StandardCharsets.UTF_8))); // throws early if malformed","typeGuard":null,"tryCatchPattern":"try {\n    layout = factory.getProcessDiagramLayout(xmlStream, imageStream);\n} catch (FlowableException e) {\n    if (e.getMessage().equals(\"Error while parsing BPMN model.\")) {\n        logger.error(\"BPMN XML malformed: {}\", e.getCause().getMessage());\n    }\n}","preventionTips":["Validate BPMN XML well-formedness in CI (xmllint)","Never pass an already-consumed InputStream","Match the XML declaration encoding to the stream bytes"],"tags":["xml","parsing","bpmn","diagram-layout"],"backgroundTag":"xml-parse-failed","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}