apache/maven · error · XMLStreamException
Entities are not supported in strict mode
Error message
Entities are not supported in strict mode
What it means
The Modello-generated reader's nextText helper (src/mdo/reader.vm) encounters an ENTITY_REFERENCE event while reading element text and the reader is in strict mode. Only the five default XML entities are tolerated when addDefaultEntities is enabled; any other entity reference (e.g. , ©, custom DTD entities) causes javax.xml.stream.XMLStreamException 'Entities are not supported in strict mode'. Non-strict mode substitutes known default entities or keeps the raw &name; text.
Source
Thrown at src/mdo/reader.vm:1092
return next;
}
}
} //-- int nextTag(XMLStreamReader)
private String nextText(XMLStreamReader parser, boolean strict) throws XMLStreamException {
int eventType = parser.getEventType();
if (eventType != XMLStreamReader.START_ELEMENT) {
throw new XMLStreamException("parser must be on START_ELEMENT to read next text", parser.getLocation(), null);
}
eventType = parser.next();
StringBuilder result = new StringBuilder();
while (true) {
if (eventType == XMLStreamReader.CHARACTERS || eventType == XMLStreamReader.CDATA) {
result.append(parser.getText());
} 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
- Replace named HTML entities in the XML with their literal UTF-8 characters or numeric references ( ).
- Remove any DOCTYPE/entity declarations from the model file.
- Read with strict=false (and addDefaultEntities enabled) if you must accept entity-laden documents.
- Sanitize upstream documentation before it is written into model XML.
Example fix
<!-- before --> <description>Use this plugin</description> <!-- after --> <description>Use this plugin</description>
Defensive patterns
Strategy: validation
Validate before calling
static final Pattern NAMED_ENTITY = Pattern.compile("&[a-zA-Z][a-zA-Z0-9]*;");
static final Set<String> DEFAULTS = Set.of("amp", "lt", "gt", "quot", "apos");
boolean hasNonDefaultEntities(String xml) {
Matcher m = NAMED_ENTITY.matcher(xml);
while (m.find()) if (!DEFAULTS.contains(m.group().substring(1, m.group().length() - 1))) return true;
return false;
} Try / catch
try {
reader.read(in, true);
} catch (XMLStreamException e) {
if (e.getMessage().contains("Entities are not supported")) { // replace with numeric refs and retry
String fixed = NAMED_ENTITY.matcher(raw).replaceAll(m -> numericRefFor(m.group()));
model = reader.read(new StringReader(fixed), true);
}
} Prevention
- Use UTF-8 characters or numeric character references in POM/model text.
- Strip DOCTYPE declarations from machine-generated model files.
- Sanitize HTML-sourced descriptions before embedding in XML.
When it happens
Trigger: Reading a POM or metadata file containing HTML-style entities such as or é in description/name elements with a strict reader. Note that standard predefined entities like & and < are resolved by the parser itself and do not trigger this; only entity references the parser reports as events (typically with a DTD or non-standard entities) do.
Common situations: Documentation text copied from HTML into <description>/<name> in pom.xml; files processed by tools that convert UTF-8 characters to named entities; custom entities defined via DOCTYPE in model files.
Related errors
- Unable to parse element '{}', must be a byte
- Expected root element '${rootTag}' but found '{}'
- Duplicated tag: '{}'
- Entities are not supported in strict mode
- Expected root element '${rootTag}' but found '{}'
AI-assisted analysis of apache/maven@e4093d4e12 (2026-08-21).
Data as JSON: /api/errors/77346bbf9fa7ba77.
Report an issue: GitHub.