apache/maven · error · XmlReaderException
Unable to read model:
Error message
Unable to read model:
What it means
DefaultModelXmlFactory.doRead funnels every failure of the actual parse/write pipeline into XmlReaderException('Unable to read model: <detail>'). The wrapped causes include XML well-formedness errors, strict-mode schema validation failures, IO problems opening the path/URL stream, and encoding issues. The exception carries the parsed StaxLocation (line/column) so the exact position in the POM can be reported.
Source
Thrown at impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultModelXmlFactory.java:149
MavenStaxReader xml = request.getTransformer() != null
? new MavenStaxReader(request.getTransformer()::transform)
: new MavenStaxReader();
xml.setAddDefaultEntities(request.isAddDefaultEntities());
if (inputStream != null) {
return xml.read(inputStream, request.isStrict(), source);
} else if (reader != null) {
return xml.read(reader, request.isStrict(), source);
} else if (path != null) {
try (InputStream is = Files.newInputStream(path)) {
return xml.read(is, request.isStrict(), source);
}
} else {
try (InputStream is = url.openStream()) {
return xml.read(is, request.isStrict(), source);
}
}
} catch (Exception e) {
throw new XmlReaderException("Unable to read model: " + getMessage(e), getLocation(e), e);
}
}
@Override
public void write(XmlWriterRequest<Model> request) throws XmlWriterException {
requireNonNull(request, "request");
Model content = requireNonNull(request.getContent(), "content");
Path path = request.getPath();
OutputStream outputStream = request.getOutputStream();
Writer writer = request.getWriter();
if (writer == null && outputStream == null && path == null) {
throw new IllegalArgumentException("writer, outputStream or path must be non null");
}
try {
MavenStaxWriter xmlWriter = new MavenStaxWriter();
xmlWriter.setAddLocationInformation(false);View on GitHub (pinned to e4093d4e12)
Solutions
- Check e.getLocation() for line/column and validate the file as XML first (xmllint or IDE XML inspection)
- For strict-mode failures, fix the offending element per the schema for the declared modelVersion, or set strict(false) if tolerant reading is acceptable
- For URL/path sources, confirm the resource is reachable/intact (re-download, check HTTP status) and that the encoding matches the XML declaration
- Report the cause chain (e.getCause()) since the top-level message only prefixes the detail
Example fix
// before
Model model = factory.read(XmlReaderRequest.builder().path(pom).build());
// after
try {
Model model = factory.read(XmlReaderRequest.builder().path(pom).build());
} catch (XmlReaderException e) {
System.err.printf('Invalid POM %s at line %d col %d: %s%n',
pom, e.getLocation().getLineNumber(), e.getLocation().getColumnNumber(), e.getMessage());
throw e;
} Defensive patterns
Strategy: try-catch
Validate before calling
// quick well-formedness check before the real read
var f = javax.xml.XMLInputFactory.newInstance();
try (var is = Files.newInputStream(pom)) {
var r = f.createXMLStreamReader(is);
while (r.hasNext()) r.next();
} Try / catch
try {
Model model = factory.read(XmlReaderRequest.builder().path(pom).build());
} catch (XmlReaderException e) {
var loc = e.getLocation(); // line/column in the POM
// report loc + e.getCause(); if strict validation, fix the element or retry with strict(false)
} Prevention
- Validate generated or edited POMs as XML before feeding them to Maven
- Check XmlReaderException.getLocation() for line/column before guessing
- Keep strict mode on in CI to catch schema violations early, off only for tolerant tooling
When it happens
Trigger: Reading a pom.xml that is not well-formed XML (unclosed tag, stray &), fails strict validation against the schema (unknown element for the declared modelVersion), cannot be opened (missing file, HTTP 404 for a URL), or has a declared encoding that does not match the bytes.
Common situations: Hand-edited POMs with XML typos or unescaped ampersands in URLs; comments or elements not valid for the modelVersion; interrupted downloads leaving truncated POMs in the local repo; CI fetching POMs over flaky HTTP; wrong file encoding after editing on Windows.
Related errors
- path, url, reader or inputStream must be non null
- Cannot read metadata from '{}': {}
- Repository identifier missing
- URL missing for repository " + id
- Repository identifier missing
AI-assisted analysis of apache/maven@e4093d4e12 (2026-08-21).
Data as JSON: /api/errors/5bc32b125352d6d4.
Report an issue: GitHub.