{"record":{"id":"0fbe2dbd74d33b7d","repo":"apache/maven","slug":"text-must-be-immediately-followed-by-end-element-a-0fbe2d","errorCode":null,"errorMessage":"TEXT must be immediately followed by END_ELEMENT and not {}","messagePattern":"TEXT must be immediately followed by END_ELEMENT and not (.+?)","errorType":"exception","errorClass":"XMLStreamException","httpStatus":null,"severity":"error","filePath":"src/mdo/reader.vm","lineNumber":1107,"sourceCode":"            } else if (eventType == XMLStreamReader.ENTITY_REFERENCE) {\n                String val = null;\n                if (strict) {\n                    throw new XMLStreamException(\"Entities are not supported in strict mode\", parser.getLocation(), null);\n                } else if (addDefaultEntities) {\n                    val = DEFAULT_ENTITIES.get(parser.getLocalName());\n                }\n                if (val != null) {\n                    result.append(val);\n                } else {\n                    result.append(\"&\").append(parser.getLocalName()).append(\";\");\n                }\n            } else if (eventType != XMLStreamReader.COMMENT) {\n                break;\n            }\n            eventType = parser.next();\n        }\n        if (eventType != XMLStreamReader.END_ELEMENT) {\n            throw new XMLStreamException(\n                    \"TEXT must be immediately followed by END_ELEMENT and not \" + eventType /*TODO: TYPES[eventType]*/, parser.getLocation(), null);\n        }\n        return result.toString();\n    }\n\n}\n","sourceCodeStart":1089,"sourceCodeEnd":1114,"githubUrl":"https://github.com/apache/maven/blob/e4093d4e120eac99d6bdce5ba67cace2f3085c97/src/mdo/reader.vm#L1089-L1114","documentation":"After collecting the text body of an element, the Modello-generated nextText helper (src/mdo/reader.vm) requires the very next event to be END_ELEMENT. If a START_ELEMENT or other event follows (mixed content such as text plus child elements), the reader throws javax.xml.stream.XMLStreamException naming the unexpected event type number (1=START_ELEMENT, 2=END_ELEMENT, 3=PROCESSING_INSTRUCTION, 4=CHARACTERS, 5=COMMENT, 8=START_DOCUMENT, etc.).","triggerScenarios":"A model XML element that the model defines as scalar text contains a child element or interleaved markup, e.g. <name>text<extra/></name>, or an XMLStreamWriter implementation emitting unexpected events. The event code in the message identifies what followed the text.","commonSituations":"Version drift: a newer XML format nests elements where the older reader model expects text; XML produced by templating engines inserting processing instructions inside text elements; hand-crafted files combining text and children.","solutions":["Look up the numeric eventType in javax.xml.stream.XMLStreamConstants to identify the stray event.","Restructure the element so scalar fields contain text only, moving child elements to model fields that allow them.","Upgrade the parsing-side model/tooling to the version matching the document format.","Re-emit the file from a conforming writer and diff to spot the structural difference."],"exampleFix":"<!-- before: mixed content in a scalar field -->\n<url>https://example.com<note>legacy</note></url>\n<!-- after -->\n<url>https://example.com</url>\n<note>legacy</note>","handlingStrategy":"validation","validationCode":"// fail fast on mixed content before parsing\nfor (Element e : scalarFieldsOf(modelXsd)) {\n    if (e.getChildCount() > 0 || !e.getTextTrim().equals(e.getText())) throw new IllegalArgumentException(\"mixed content in \" + e.getQualifiedName());\n}","typeGuard":null,"tryCatchPattern":"try {\n    reader.read(in, true);\n} catch (XMLStreamException e) {\n    // parse the trailing number to identify the stray event, then restructure the XML\n}","preventionTips":["Match reader version to document format version.","Do not post-process model XML with templating tools that inject markup.","Round-trip test: write then read every model file you emit."],"tags":["xml","stax","modello","mixed-content","parser-state"],"backgroundTag":"xml-mixed-content","analyzedSha":"e4093d4e120eac99d6bdce5ba67cace2f3085c97","analyzedAt":"2026-08-21T22:58:24.034Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}