{"record":{"id":"6691bece714128aa","repo":"apache/maven","slug":"unable-to-read-settings","errorCode":null,"errorMessage":"Unable to read settings: ","messagePattern":"Unable to read settings: ","errorType":"exception","errorClass":"XmlReaderException","httpStatus":null,"severity":"error","filePath":"impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultSettingsXmlFactory.java","lineNumber":70,"sourceCode":"        if (reader == null && inputStream == null) {\n            throw new IllegalArgumentException(\"reader or inputStream must be non null\");\n        }\n        try {\n            InputSource source = null;\n            if (request.getModelId() != null || request.getLocation() != null) {\n                source = InputSource.of(request.getLocation());\n            }\n            SettingsStaxReader xml = request.getTransformer() != null\n                    ? new SettingsStaxReader(request.getTransformer()::transform)\n                    : new SettingsStaxReader();\n            xml.setAddDefaultEntities(request.isAddDefaultEntities());\n            if (reader != null) {\n                return xml.read(reader, request.isStrict(), source);\n            } else {\n                return xml.read(inputStream, request.isStrict(), source);\n            }\n        } catch (Exception e) {\n            throw new XmlReaderException(\"Unable to read settings: \" + getMessage(e), getLocation(e), e);\n        }\n    }\n\n    @Override\n    public void write(XmlWriterRequest<Settings> request) throws XmlWriterException {\n        nonNull(request, \"request\");\n        Settings content = nonNull(request.getContent(), \"content\");\n        OutputStream outputStream = request.getOutputStream();\n        Writer writer = request.getWriter();\n        if (writer == null && outputStream == null) {\n            throw new IllegalArgumentException(\"writer or outputStream must be non null\");\n        }\n        try {\n            SettingsStaxWriter xmlWriter = new SettingsStaxWriter();\n            xmlWriter.setAddLocationInformation(false);\n\n            Function<Object, String> formatter = request.getInputLocationFormatter();\n            if (formatter != null) {","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/apache/maven/blob/e4093d4e120eac99d6bdce5ba67cace2f3085c97/impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultSettingsXmlFactory.java#L52-L88","documentation":"Wrapper thrown when parsing a Settings document fails: malformed settings.xml, strict-mode rejection of unknown elements, or IO errors while reading the supplied Reader/InputStream. The cause is preserved; STaX causes carry line and column information that this factory appends to the message.","triggerScenarios":"Malformed or truncated settings.xml fed via reader/inputStream; strict=true with unrecognized tags; a stream that throws during read; wrong character encoding producing parse failures.","commonSituations":"Corrupted user settings after a crashed editor; settings files saved in an unexpected encoding; settings with constructs (entities, DTDs) the reader rejects.","solutions":["Unwrap getCause() for the exact line and column of the parse failure","Try .strict(false) on the request if unknown elements are acceptable","Check encoding and well-formedness with an XML lint tool before passing the file","If entity expansion is involved, review the request's addDefaultEntities setting"],"exampleFix":"// before\nSettings s = settingsXmlFactory.read(XmlReaderRequest.builder()\n    .reader(reader)\n    .build()); // strict default can reject unknown elements\n\n// after\nSettings s = settingsXmlFactory.read(XmlReaderRequest.builder()\n    .reader(reader)\n    .strict(false)\n    .build());","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    Settings s = settingsXmlFactory.read(req);\n} catch (XmlReaderException e) {\n    Throwable cause = e.getCause();\n    // STaX cause carries line/column; surface it, do not retry blindly\n    log.error(\"settings parse failed: {}\", e.getMessage(), cause);\n}","preventionTips":["Lint settings.xml after manual edits","Standardize on UTF-8 for settings files","Use strict(false) only when foreign extensions in settings are expected"],"tags":["maven","settings","xml","parse"],"backgroundTag":"xml-parse-failed","analyzedSha":"e4093d4e120eac99d6bdce5ba67cace2f3085c97","analyzedAt":"2026-08-21T22:58:24.034Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}