{"record":{"id":"f924b4a65d606683","repo":"apache/maven","slug":"invalid-namespace-model-getnamespaceuri","errorCode":null,"errorMessage":"Invalid namespace '\" + model.getNamespaceUri() + \"' for model version \" + model.getModelVersion()","messagePattern":"Invalid namespace '\" \\+ model\\.getNamespaceUri\\(\\) \\+ \"' for model version \" \\+ model\\.getModelVersion\\(\\)","errorType":"validation","errorClass":"XmlReaderException","httpStatus":null,"severity":"error","filePath":"impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultModelXmlFactory.java","lineNumber":68,"sourceCode":"import org.apache.maven.api.xml.XmlService;\nimport org.apache.maven.model.v4.MavenStaxReader;\nimport org.apache.maven.model.v4.MavenStaxWriter;\n\nimport static java.util.Objects.requireNonNull;\nimport static org.apache.maven.impl.StaxLocation.getLocation;\nimport static org.apache.maven.impl.StaxLocation.getMessage;\n\n@Named\n@Singleton\npublic class DefaultModelXmlFactory implements ModelXmlFactory {\n    @Override\n    @Nonnull\n    public Model read(@Nonnull XmlReaderRequest request) throws XmlReaderException {\n        requireNonNull(request, \"request\");\n        Model model = doRead(request);\n        if (isModelVersionGreaterThan400(model)\n                && !model.getNamespaceUri().startsWith(\"http://maven.apache.org/POM/\")) {\n            throw new XmlReaderException(\n                    \"Invalid namespace '\" + model.getNamespaceUri() + \"' for model version \" + model.getModelVersion(),\n                    null,\n                    null);\n        }\n        return model;\n    }\n\n    private boolean isModelVersionGreaterThan400(Model model) {\n        String version = model.getModelVersion();\n        if (version == null) {\n            return false;\n        }\n        try {\n            String[] parts = version.split(\"\\\\.\");\n            int major = Integer.parseInt(parts[0]);\n            int minor = parts.length > 1 ? Integer.parseInt(parts[1]) : 0;\n            return major > 4 || (major == 4 && minor > 0);\n        } catch (NumberFormatException | IndexOutOfBoundsException e) {","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/apache/maven/blob/e4093d4e120eac99d6bdce5ba67cace2f3085c97/impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultModelXmlFactory.java#L50-L86","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"<!-- before -->\n<project>\n  <modelVersion>4.1.0</modelVersion>\n  ...\n\n<!-- after -->\n<project xmlns=\"http://maven.apache.org/POM/4.1.0\"\n         xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n         xsi:schemaLocation=\"http://maven.apache.org/POM/4.1.0 https://maven.apache.org/xsd/maven-4.1.0.xsd\">\n  <modelVersion>4.1.0</modelVersion>\n  ...","handlingStrategy":"validation","validationCode":"// before reading a 4.1+ POM, verify the root namespace\nvar factory = javax.xml.XMLInputFactory.newInstance();\ntry (var r = factory.createXMLStreamReader(Files.newInputStream(pom))) {\n    r.nextTag();\n    if (!'http://maven.apache.org/POM/'.regionMatches(\n            true, 0, r.getNamespaceURI() == null ? '' : r.getNamespaceURI(), 0, Math.min(27, r.getNamespaceURI() == null ? 0 : r.getNamespaceURI().length()))) {\n        throw new IllegalArgumentException('POM must use the http://maven.apache.org/POM/ namespace');\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["maven","pom","xml","namespace","model-version"],"backgroundTag":"xml-namespace-mismatch","analyzedSha":"e4093d4e120eac99d6bdce5ba67cace2f3085c97","analyzedAt":"2026-08-21T22:58:24.034Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}