{"record":{"id":"804eb323bae56e8f","repo":"apache/maven","slug":"cannot-be-null","errorCode":null,"errorMessage":"{} cannot be null","messagePattern":"(.+?) cannot be null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultSettingsXmlFactory.java","lineNumber":106,"sourceCode":"            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) {\n            throw new XmlWriterException(\"Unable to write settings: \" + getMessage(e), getLocation(e), e);\n        }\n    }\n\n    static <T> T nonNull(T t, String name) {\n        if (t == null) {\n            throw new IllegalArgumentException(name + \" cannot be null\");\n        }\n        return t;\n    }\n}\n","sourceCodeStart":88,"sourceCodeEnd":111,"githubUrl":"https://github.com/apache/maven/blob/e4093d4e120eac99d6bdce5ba67cace2f3085c97/impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultSettingsXmlFactory.java#L88-L111","documentation":"Generic null guard used by DefaultSettingsXmlFactory for its request and content parameters; the message interpolates the parameter name, so it surfaces as 'request cannot be null' or 'content cannot be null'. read() rejects a null request; write() rejects a null request and a request whose getContent() is null.","triggerScenarios":"Passing a null XmlReaderRequest/XmlWriterRequest to read/write; calling write with a request built without .content(settings).","commonSituations":"Optional-based call chains that hand null through; builder refactors that drop the content line; helper methods that accept nullable requests.","solutions":["Always set .content(settings) on write requests","Null-check the request object before the call","Add your own requireNonNull checks earlier so failures carry your call-site context"],"exampleFix":"// before\nsettingsXmlFactory.write(XmlWriterRequest.builder()\n    .writer(sw)\n    .build()); // throws: content cannot be null\n\n// after\nsettingsXmlFactory.write(XmlWriterRequest.builder()\n    .content(settings)\n    .writer(sw)\n    .build());","handlingStrategy":"validation","validationCode":"Objects.requireNonNull(request, \"request\");\nif (writing && request.getContent() == null) {\n    throw new IllegalStateException(\"settings write requires non-null content\");\n}\n// now safe to call the factory","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never pass Optional.orElse(null) results into the factory","Set .content(...) in the same builder expression as the target"],"tags":["maven","settings","null-check","validation"],"backgroundTag":"missing-required-argument","analyzedSha":"e4093d4e120eac99d6bdce5ba67cace2f3085c97","analyzedAt":"2026-08-21T22:58:24.034Z","schemaVersion":2},"datasetVersion":"2026-08-22T04:17:13.399Z"}