{"record":{"id":"e21283dc94cf578b","repo":"flowable/flowable-engine","slug":"error-while-reading-the-bpmn-2-0-xml","errorCode":null,"errorMessage":"Error while reading the BPMN 2.0 XML","messagePattern":"Error while reading the BPMN 2\\.0 XML","errorType":"exception","errorClass":"XMLException","httpStatus":null,"severity":"error","filePath":"modules/flowable-bpmn-converter/src/main/java/org/flowable/bpmn/converter/BpmnXMLConverter.java","lineNumber":301,"sourceCode":"        if (xif.isPropertySupported(XMLConstants.ACCESS_EXTERNAL_DTD)) {\n            xif.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, \"\");\n        }\n        \n        if (xif.isPropertySupported(XMLConstants.ACCESS_EXTERNAL_SCHEMA)) {\n            xif.setProperty(XMLConstants.ACCESS_EXTERNAL_SCHEMA, \"\");\n        }\n\n        if (validateSchema) {\n            try (InputStreamReader in = new InputStreamReader(inputStreamProvider.getInputStream(), encoding)) {\n                if (!enableSafeBpmnXml) {\n                    validateModel(inputStreamProvider);\n                } else {\n                    validateModel(new FlowableXMLStreamReader(xif.createXMLStreamReader(in)));\n                }\n            } catch (UnsupportedEncodingException e) {\n                throw new XMLException(\"The bpmn 2.0 xml is not properly encoded\", e);\n            } catch(XMLStreamException e){\n                throw new XMLException(\"Error while reading the BPMN 2.0 XML\", e);\n            } catch(Exception e){\n                throw new XMLException(e.getMessage(), e);\n            }\n        }\n        // The input stream is closed after schema validation\n        try (InputStreamReader in = new InputStreamReader(inputStreamProvider.getInputStream(), encoding)) {\n            // XML conversion\n            return convertToBpmnModel(xif.createXMLStreamReader(in));\n        } catch (UnsupportedEncodingException e) {\n            throw new XMLException(\"The bpmn 2.0 xml is not properly encoded\", e);\n        } catch (XMLStreamException e) {\n            throw new XMLException(\"Error while reading the BPMN 2.0 XML\", e);\n        } catch (IOException e) {\n            throw new XMLException(e.getMessage(), e);\n        }\n    }\n\n    public BpmnModel convertToBpmnModel(XMLStreamReader xtr) {","sourceCodeStart":283,"sourceCodeEnd":319,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-bpmn-converter/src/main/java/org/flowable/bpmn/converter/BpmnXMLConverter.java#L283-L319","documentation":"BpmnXMLConverter.convertToBpmnModel(InputStreamProvider, String) wraps any XMLStreamException raised while the StAX reader parses the first pass of the BPMN document (schema validation / initial convert) into XMLException with this fixed message. It signals the XML itself could not be read by the underlying parser, not that it failed validation rules.","triggerScenarios":"Calling convertToBpmnModel(inputStreamProvider, encoding) where the input stream yields malformed XML (unclosed tags, invalid characters, truncated document) causing the underlying XMLStreamReader to throw XMLStreamException during validateModel or the initial read.","commonSituations":"Deploying a .bpmn/.bpmn20.xml file that was truncated on upload, hand-edited with a typo, saved with an encoding mismatch, or produced by a tool emitting invalid XML; also reading a stream already consumed by a previous parse attempt.","solutions":["Validate the BPMN XML with an XML parser (xmllint or IDE) to find the malformation and fix the document.","Check the getCause() XMLStreamException location (line/column) in logs to pinpoint the broken spot.","Ensure the InputStream is fresh and not already consumed; re-open the resource before converting.","Verify the declared encoding matches the actual bytes of the file."],"exampleFix":"// before\nInputStream is = new FileInputStream(f);\nbpmnXmlConverter.convertToBpmnModel(new DefaultInputStreamProvider(is), \"UTF-8\"); // stream reused earlier\n// after\ntry (InputStream is = new FileInputStream(f)) {\n    BpmnModel model = bpmnXmlConverter.convertToBpmnModel(new DefaultInputStreamProvider(is), \"UTF-8\");\n} catch (XMLException e) {\n    logger.error(\"Invalid BPMN XML at {}\", e.getCause());\n}","handlingStrategy":"validation","validationCode":"// Pre-validate the BPMN source is well-formed XML before converting\nbyte[] bytes = readAll(provider);\nDocumentBuilderFactory f = DocumentBuilderFactory.newInstance();\nf.setNamespaceAware(true);\nf.newDocumentBuilder().parse(new ByteArrayInputStream(bytes)); // throws SAXParseException with line/col if malformed","typeGuard":null,"tryCatchPattern":"try {\n    BpmnModel m = converter.convertToBpmnModel(provider, \"UTF-8\");\n} catch (XMLException e) {\n    Throwable c = e.getCause();\n    if (c instanceof XMLStreamException xse) {\n        throw new DeploymentException(\"Invalid BPMN XML at line \" + xse.getLocation().getLineNumber(), e);\n    }\n    throw e;\n}","preventionTips":["Validate every .bpmn file with an XML parser/linter before deployment","Never reuse a consumed InputStream; open a fresh one per conversion","Keep BPMN files under version control so corrupted uploads are diffable"],"tags":["java","xml","bpmn","parse-error"],"backgroundTag":"json-parse-error","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"}