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
nextText accumulates text events (CHARACTERS, CDATA, resolved entities; comments skipped) and requires the element to close immediately after the text. Any other event - practically a nested START_ELEMENT - is mixed content, which a flat string field cannot represent, so the reader throws with the offending event code appended.
Source
Thrown at src/mdo/reader-stax.vm:701
} 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 = DefaultEntitiesHolder.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();
}
#if ( $locationTracking )
private XmlNode buildXmlNode(XMLStreamReader parser, InputSource inputSrc) throws XMLStreamException {
return XmlService.read(parser,
addLocationInformation
? p -> InputLocation.of(p.getLocation().getLineNumber(), p.getLocation().getColumnNumber(), inputSrc)
: null);
}
#else
private XmlNode buildXmlNode(XMLStreamReader parser) throws XMLStreamException {
return XmlService.read(parser);
}
#end
View on GitHub (pinned to e4093d4e12)
Solutions
- Remove the nested markup, or put the entire rich-text run into a CDATA section so it stays one text node.
- If structured children are required there, the model must define them - a model change, not a caller-side fix.
- Reject such documents at intake with a targeted message.
Example fix
<!-- before --> <description>see <code>foo</code> here</description> <!-- after --> <description><![CDATA[see <code>foo</code> here]]></description>
Defensive patterns
Strategy: try-catch
Try / catch
try {
Model model = reader.read(in, true);
} catch (XMLStreamException e) {
if (e.getMessage() != null && e.getMessage().startsWith("TEXT must be immediately followed")) {
// mixed content in a text field: report location, ask producer to escape/CDATA the text
}
throw e;
} Prevention
- Keep markup out of text fields; wrap rich text in CDATA.
- Escape tag-like content when generating XML.
- Validate with XSD - most schemas reject mixed content in these fields.
When it happens
Trigger: A text-only model field contains markup: <description>see <code>foo</code> here</description>, or any child element plus text inside a field the model defines as a simple string.
Common situations: HTML snippets pasted into description/name fields; templating systems injecting tags into element bodies.
Related errors
- Expected root element '${rootTag}' but found '{}'
- Duplicated tag: '${rootTag}'
- Expected root element '${rootTag}' but found no element at a
- Duplicated tag: '{}'
- Unable to parse element '{}', must be an integer
AI-assisted analysis of apache/maven@e4093d4e12 (2026-08-21).
Data as JSON: /api/errors/7153677de807e04d.
Report an issue: GitHub.