{"record":{"id":"428e4327778b7e6c","repo":"apache/maven","slug":"writer-outputstream-or-path-must-be-non-null","errorCode":null,"errorMessage":"writer, outputStream or path must be non null","messagePattern":"writer, outputStream or path must be non null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultModelXmlFactory.java","lineNumber":162,"sourceCode":"                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);\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 if (outputStream != null) {\n                xmlWriter.write(outputStream, content);\n            } else {","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/apache/maven/blob/e4093d4e120eac99d6bdce5ba67cace2f3085c97/impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultModelXmlFactory.java#L144-L180","documentation":"Thrown by DefaultModelXmlFactory.write(XmlWriterRequest<Model>) when the request carries no output target. The method accepts a Writer, an OutputStream or a Path and checks all three; if writer, outputStream and path are all null it throws IllegalArgumentException before any serialization starts. This is a caller-contract violation, not an environmental problem.","triggerScenarios":"Building a XmlWriterRequest for a Model without calling .writer(...), .outputStream(...) or .path(...), then passing it to ModelXmlFactory.write (or ModelProcessor.write). Also occurs when the target is set conditionally and that branch is not taken at runtime.","commonSituations":"Refactoring write code that previously used a hard-coded file; copy-pasting a read-side request (modelId/location only) and forgetting the output target; builder chains where the target comes from a variable that is null.","solutions":["Set exactly one output target on the request: .path(Paths.get(\"pom.xml\")), .outputStream(os) or .writer(new StringWriter())","If the target is dynamic, verify at least one of getWriter(), getOutputStream(), getPath() is non-null before calling write","Fail fast at request-build time in your own code so the error carries your context, not the factory's generic message"],"exampleFix":"// before\nXmlWriterRequest<Model> req = XmlWriterRequest.builder()\n    .content(model)\n    .build();\nmodelXmlFactory.write(req); // throws: no output target\n\n// after\nXmlWriterRequest<Model> req = XmlWriterRequest.builder()\n    .content(model)\n    .path(Paths.get(\"pom.xml\"))\n    .build();\nmodelXmlFactory.write(req);","handlingStrategy":"validation","validationCode":"XmlWriterRequest<Model> req = XmlWriterRequest.builder()\n    .content(model)\n    .build();\nif (req.getWriter() == null && req.getOutputStream() == null && req.getPath() == null) {\n    throw new IllegalStateException(\"model write request has no output target\");\n}\nmodelXmlFactory.write(req);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Configure the output target in the same builder expression as the content so the two cannot diverge","Treat a request without exactly one target as a bug and assert it in unit tests"],"tags":["maven","xml","model","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"}