{"record":{"id":"0a55816d36a104ad","repo":"apache/maven","slug":"writer-outputstream-or-path-must-be-non-null-0a5581","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/DefaultPluginXmlFactory.java","lineNumber":89,"sourceCode":"            } else {\n                try (InputStream is = url.openStream()) {\n                    return xml.read(is, request.isStrict());\n                }\n            }\n        } catch (Exception e) {\n            throw new XmlReaderException(\"Unable to read plugin: \" + getMessage(e), getLocation(e), e);\n        }\n    }\n\n    @Override\n    public void write(XmlWriterRequest<PluginDescriptor> request) throws XmlWriterException {\n        requireNonNull(request, \"request\");\n        PluginDescriptor content = requireNonNull(request.getContent(), \"content\");\n        Path path = request.getPath();\n        OutputStream outputStream = request.getOutputStream();\n        Writer writer = request.getWriter();\n        if (writer == null && outputStream == null && path == null) {\n            throw new IllegalArgumentException(\"writer, outputStream or path must be non null\");\n        }\n        try {\n            if (writer != null) {\n                new PluginDescriptorStaxWriter().write(writer, content);\n            } else if (outputStream != null) {\n                new PluginDescriptorStaxWriter().write(outputStream, content);\n            } else {\n                try (OutputStream os = Files.newOutputStream(path)) {\n                    new PluginDescriptorStaxWriter().write(os, content);\n                }\n            }\n        } catch (Exception e) {\n            throw new XmlWriterException(\"Unable to write plugin: \" + getMessage(e), getLocation(e), e);\n        }\n    }\n\n    /**\n     * Simply parse the given xml string.","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/apache/maven/blob/e4093d4e120eac99d6bdce5ba67cace2f3085c97/impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultPluginXmlFactory.java#L71-L107","documentation":"Thrown by DefaultPluginXmlFactory.write(XmlWriterRequest<PluginDescriptor>) when the request has no output target: writer, outputStream and path are all null. The factory refuses the call before any serialization starts. Caller-contract violation, not environmental.","triggerScenarios":"Calling PluginXmlFactory.write with a request built without .writer(...), .outputStream(...) or .path(...).","commonSituations":"Round-tripping a descriptor (read then write) where the write request is assembled separately and the target is forgotten; tests that set only the content for in-memory writes.","solutions":["Set one of .writer(...), .outputStream(...) or .path(...) on the request","In tests, use .writer(new StringWriter()) for in-memory output","Assert the target is present before the call so failures surface in your own terms"],"exampleFix":"// before\npluginXmlFactory.write(XmlWriterRequest.builder()\n    .content(descriptor)\n    .build()); // throws: no output target\n\n// after\nStringWriter sw = new StringWriter();\npluginXmlFactory.write(XmlWriterRequest.builder()\n    .content(descriptor)\n    .writer(sw)\n    .build());","handlingStrategy":"validation","validationCode":"XmlWriterRequest<PluginDescriptor> req = XmlWriterRequest.builder()\n    .content(descriptor)\n    .build();\nif (req.getWriter() == null && req.getOutputStream() == null && req.getPath() == null) {\n    throw new IllegalStateException(\"descriptor write request has no output target\");\n}\npluginXmlFactory.write(req);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["In tests, default to .writer(new StringWriter()) for in-memory round-trips","Set content and target together in one builder expression"],"tags":["maven","xml","plugin-descriptor","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"}