apache/maven · error · XMLStreamException
TEXT must be immediately followed by END_ELEMENT and not {}
Error message
TEXT must be immediately followed by END_ELEMENT and not {} What it means
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.).
Source
Thrown at src/mdo/reader.vm:1107
} else if (eventType == XMLStreamReader.ENTITY_REFERENCE) {
String val = null;
if (strict) {
throw new XMLStreamException("Entities are not supported in strict mode", parser.getLocation(), null);
} else if (addDefaultEntities) {
val = DEFAULT_ENTITIES.get(parser.getLocalName());
}
if (val != null) {
result.append(val);
} else {
result.append("&").append(parser.getLocalName()).append(";");
}
} else if (eventType != XMLStreamReader.COMMENT) {
break;
}
eventType = parser.next();
}
if (eventType != XMLStreamReader.END_ELEMENT) {
throw new XMLStreamException(
"TEXT must be immediately followed by END_ELEMENT and not " + eventType /*TODO: TYPES[eventType]*/, parser.getLocation(), null);
}
return result.toString();
}
}
View on GitHub (pinned to e4093d4e12)
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.
Example fix
<!-- before: mixed content in a scalar field --> <url>https://example.com<note>legacy</note></url> <!-- after --> <url>https://example.com</url> <note>legacy</note>
Defensive patterns
Strategy: validation
Validate before calling
// fail fast on mixed content before parsing
for (Element e : scalarFieldsOf(modelXsd)) {
if (e.getChildCount() > 0 || !e.getTextTrim().equals(e.getText())) throw new IllegalArgumentException("mixed content in " + e.getQualifiedName());
} Try / catch
try {
reader.read(in, true);
} catch (XMLStreamException e) {
// parse the trailing number to identify the stray event, then restructure the XML
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- parser must be on START_ELEMENT to read next text
- Expected root element '${rootTag}' but found '{}'
- Duplicated tag: '{}'
- parser must be on START_ELEMENT to read next text
- TEXT must be immediately followed by END_ELEMENT and not {}
AI-assisted analysis of apache/maven@e4093d4e12 (2026-08-21).
Data as JSON: /api/errors/0fbe2dbd74d33b7d.
Report an issue: GitHub.