apache/maven · error · XmlReaderException
Invalid namespace '" + model.getNamespaceUri() + "' for mode
Error message
Invalid namespace '" + model.getNamespaceUri() + "' for model version " + model.getModelVersion()
What it means
DefaultModelXmlFactory.read enforces that models with modelVersion greater than 4.0.0 must carry an XML namespace starting with http://maven.apache.org/POM/. This guards the Maven 4 consumed POM format: a 4.1+ model without the official namespace (wrong URI, or namespace-less XML) is rejected with XmlReaderException before the model is returned.
Source
Thrown at impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultModelXmlFactory.java:68
import org.apache.maven.api.xml.XmlService;
import org.apache.maven.model.v4.MavenStaxReader;
import org.apache.maven.model.v4.MavenStaxWriter;
import static java.util.Objects.requireNonNull;
import static org.apache.maven.impl.StaxLocation.getLocation;
import static org.apache.maven.impl.StaxLocation.getMessage;
@Named
@Singleton
public class DefaultModelXmlFactory implements ModelXmlFactory {
@Override
@Nonnull
public Model read(@Nonnull XmlReaderRequest request) throws XmlReaderException {
requireNonNull(request, "request");
Model model = doRead(request);
if (isModelVersionGreaterThan400(model)
&& !model.getNamespaceUri().startsWith("http://maven.apache.org/POM/")) {
throw new XmlReaderException(
"Invalid namespace '" + model.getNamespaceUri() + "' for model version " + model.getModelVersion(),
null,
null);
}
return model;
}
private boolean isModelVersionGreaterThan400(Model model) {
String version = model.getModelVersion();
if (version == null) {
return false;
}
try {
String[] parts = version.split("\\.");
int major = Integer.parseInt(parts[0]);
int minor = parts.length > 1 ? Integer.parseInt(parts[1]) : 0;
return major > 4 || (major == 4 && minor > 0);
} catch (NumberFormatException | IndexOutOfBoundsException e) {View on GitHub (pinned to e4093d4e12)
Solutions
- Declare the official namespace on the root element: <project xmlns="http://maven.apache.org/POM/4.1.0" ...> with matching xsi:schemaLocation
- Keep modelVersion at 4.0.0 if you cannot add the namespace (the check only applies above 4.0.0)
- When writing models programmatically, use ModelXmlFactory.write so the correct namespace is emitted
Example fix
<!-- before -->
<project>
<modelVersion>4.1.0</modelVersion>
...
<!-- after -->
<project xmlns="http://maven.apache.org/POM/4.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.1.0 https://maven.apache.org/xsd/maven-4.1.0.xsd">
<modelVersion>4.1.0</modelVersion>
... Defensive patterns
Strategy: validation
Validate before calling
// before reading a 4.1+ POM, verify the root namespace
var factory = javax.xml.XMLInputFactory.newInstance();
try (var r = factory.createXMLStreamReader(Files.newInputStream(pom))) {
r.nextTag();
if (!'http://maven.apache.org/POM/'.regionMatches(
true, 0, r.getNamespaceURI() == null ? '' : r.getNamespaceURI(), 0, Math.min(27, r.getNamespaceURI() == null ? 0 : r.getNamespaceURI().length()))) {
throw new IllegalArgumentException('POM must use the http://maven.apache.org/POM/ namespace');
}
} Prevention
- Always emit xmlns on generated POMs, ideally via ModelXmlFactory.write
- Keep modelVersion and namespace consistent (4.0.0 without new constraints, 4.1.0 with the official namespace)
- Lint hand-edited 4.1 POMs for the xmlns attribute in CI
When it happens
Trigger: Reading a pom.xml whose <project> root declares modelVersion 4.1.0 (or higher) but omits xmlns or uses a different namespace (e.g. a custom schema or the 4.0.0 namespace with a 4.1.0 modelVersion); hand-generated POMs written by tools that drop the xmlns attribute.
Common situations: Programmatically generated POMs missing the xmlns attribute; upgrading modelVersion to 4.1.0 while keeping an old/no namespace; transforming POMs with XML tooling that strips namespaces; copy-pasting a 4.1 skeleton from a blog that omitted xmlns.
Related errors
- path, url, reader or inputStream must be non null
- Unable to read model:
- Repository list contains duplicate entries. Each repository
- Repository list contains null entries. All repository entrie
- Cannot read metadata from '{}': {}
AI-assisted analysis of apache/maven@e4093d4e12 (2026-08-21).
Data as JSON: /api/errors/f924b4a65d606683.
Report an issue: GitHub.