{"record":{"id":"5bc32b125352d6d4","repo":"apache/maven","slug":"unable-to-read-model","errorCode":null,"errorMessage":"Unable to read model: ","messagePattern":"Unable to read model: ","errorType":"exception","errorClass":"XmlReaderException","httpStatus":null,"severity":"error","filePath":"impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultModelXmlFactory.java","lineNumber":149,"sourceCode":"            MavenStaxReader xml = request.getTransformer() != null\n                    ? new MavenStaxReader(request.getTransformer()::transform)\n                    : new MavenStaxReader();\n            xml.setAddDefaultEntities(request.isAddDefaultEntities());\n            if (inputStream != null) {\n                return xml.read(inputStream, request.isStrict(), source);\n            } else if (reader != null) {\n                return xml.read(reader, request.isStrict(), source);\n            } else if (path != null) {\n                try (InputStream is = Files.newInputStream(path)) {\n                    return xml.read(is, request.isStrict(), source);\n                }\n            } else {\n                try (InputStream is = url.openStream()) {\n                    return xml.read(is, request.isStrict(), source);\n                }\n            }\n        } catch (Exception e) {\n            throw new XmlReaderException(\"Unable to read model: \" + getMessage(e), getLocation(e), e);\n        }\n    }\n\n    @Override\n    public void write(XmlWriterRequest<Model> request) throws XmlWriterException {\n        requireNonNull(request, \"request\");\n        Model content = requireNonNull(request.getContent(), \"content\");\n        Path path = request.getPath();\n        OutputStream outputStream = request.getOutputStream();\n        Writer writer = request.getWriter();\n\n        if (writer == null && outputStream == null && path == null) {\n            throw new IllegalArgumentException(\"writer, outputStream or path must be non null\");\n        }\n\n        try {\n            MavenStaxWriter xmlWriter = new MavenStaxWriter();\n            xmlWriter.setAddLocationInformation(false);","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/apache/maven/blob/e4093d4e120eac99d6bdce5ba67cace2f3085c97/impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultModelXmlFactory.java#L131-L167","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nModel model = factory.read(XmlReaderRequest.builder().path(pom).build());\n\n// after\ntry {\n    Model model = factory.read(XmlReaderRequest.builder().path(pom).build());\n} catch (XmlReaderException e) {\n    System.err.printf('Invalid POM %s at line %d col %d: %s%n',\n            pom, e.getLocation().getLineNumber(), e.getLocation().getColumnNumber(), e.getMessage());\n    throw e;\n}","handlingStrategy":"try-catch","validationCode":"// quick well-formedness check before the real read\nvar f = javax.xml.XMLInputFactory.newInstance();\ntry (var is = Files.newInputStream(pom)) {\n    var r = f.createXMLStreamReader(is);\n    while (r.hasNext()) r.next();\n}","typeGuard":null,"tryCatchPattern":"try {\n    Model model = factory.read(XmlReaderRequest.builder().path(pom).build());\n} catch (XmlReaderException e) {\n    var loc = e.getLocation(); // line/column in the POM\n    // report loc + e.getCause(); if strict validation, fix the element or retry with strict(false)\n}","preventionTips":["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"],"tags":["maven","pom","xml","parsing","validation"],"backgroundTag":"xml-parse-error","analyzedSha":"e4093d4e120eac99d6bdce5ba67cace2f3085c97","analyzedAt":"2026-08-21T22:58:24.034Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}