{"record":{"id":"d800d2b3a4e3fc5b","repo":"apache/maven","slug":"writer-or-outputstream-must-be-non-null","errorCode":null,"errorMessage":"writer or outputStream must be non null","messagePattern":"writer or outputStream must be non null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultSettingsXmlFactory.java","lineNumber":81,"sourceCode":"            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) {\n                xmlWriter.setAddLocationInformation(true);\n                Function<InputLocation, String> adapter = formatter::apply;\n                xmlWriter.setStringFormatter(adapter);\n            }\n\n            if (writer != null) {\n                xmlWriter.write(writer, content);\n            } else {\n                xmlWriter.write(outputStream, content);\n            }\n        } catch (Exception e) {","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/apache/maven/blob/e4093d4e120eac99d6bdce5ba67cace2f3085c97/impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultSettingsXmlFactory.java#L63-L99","documentation":"DefaultSettingsXmlFactory.write accepts only a Writer or an OutputStream - there is no path support on this factory. If both are null the call is rejected with IllegalArgumentException before serialization starts.","triggerScenarios":"Building a write request for Settings with only .path(...) set (ignored here), or with no output target at all.","commonSituations":"Porting write code from the model factory, which does support path targets; tests that set only the content.","solutions":["Pass .writer(...) or .outputStream(...) on the request","To write a file, open it yourself: .outputStream(Files.newOutputStream(settingsPath)) inside try-with-resources","For in-memory output use .writer(new StringWriter())"],"exampleFix":"// before\nsettingsXmlFactory.write(XmlWriterRequest.builder()\n    .content(settings)\n    .path(settingsPath) // no path support on this factory\n    .build()); // throws\n\n// after\ntry (OutputStream os = Files.newOutputStream(settingsPath)) {\n    settingsXmlFactory.write(XmlWriterRequest.builder()\n        .content(settings)\n        .outputStream(os)\n        .build());\n}","handlingStrategy":"validation","validationCode":"XmlWriterRequest<Settings> req = XmlWriterRequest.builder()\n    .content(settings)\n    .build();\nif (req.getWriter() == null && req.getOutputStream() == null) {\n    throw new IllegalStateException(\"settings write request has no writer or outputStream\");\n}\nsettingsXmlFactory.write(req);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Do not port .path(...) from the model factory: settings writes need an open stream","Wrap file writes in try-with-resources so the stream closes even on failure"],"tags":["maven","settings","xml","writer","null-check"],"backgroundTag":"missing-required-argument","analyzedSha":"e4093d4e120eac99d6bdce5ba67cace2f3085c97","analyzedAt":"2026-08-21T22:58:24.034Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}