{"record":{"id":"7064013fb5155a77","repo":"zaproxy/zaproxy","slug":"attempt-to-addparameters-null-ignored","errorCode":null,"errorMessage":"Attempt to addParameters(null) ignored","messagePattern":"Attempt to addParameters\\(null\\) ignored","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"zap/src/main/java/org/parosproxy/paros/network/GenericMethod.java","lineNumber":269,"sourceCode":"        if (param == null) {\n            throw new IllegalArgumentException(\"NameValuePair may not be null\");\n        }\n        addParameter(param.getName(), param.getValue());\n    }\n\n    /**\n     * Adds an array of parameters to be used in the POST request body. Logs a\n     * warning if the parameters argument is null.\n     *\n     * @param parameters The array of parameters to add.\n     *\n     * @since 2.0\n     */\n    public void addParameters(NameValuePair[] parameters) {\n        log.trace(\"enter PostMethod.addParameters(NameValuePair[])\");\n\n        if (parameters == null) {\n            log.warn(\"Attempt to addParameters(null) ignored\");\n        } else {\n            super.clearRequestBody();\n            for (int i = 0; i < parameters.length; i++) {\n                this.params.add(parameters[i]);\n            }\n        }\n    }\n\n    /**\n     * Removes all parameters with the given paramName. If there is more than\n     * one parameter with the given paramName, all of them are removed.  If\n     * there is just one, it is removed.  If there are none, then the request\n     * is ignored.\n     *\n     * @param paramName The parameter name to remove.\n     *\n     * @return true if at least one parameter was removed\n     *","sourceCodeStart":251,"sourceCodeEnd":287,"githubUrl":"https://github.com/zaproxy/zaproxy/blob/9d1970a436b1b189bfb588fc88864c80d9baf6a5/zap/src/main/java/org/parosproxy/paros/network/GenericMethod.java#L251-L287","documentation":"GenericMethod.addParameters(NameValuePair[]) logs a warning and returns without modifying the request body when handed a null array. The call is otherwise a no-op-safe defensive guard inherited from PostMethod-style semantics; the request body is simply left unchanged (or empty for a fresh method).","triggerScenarios":"Calling method.addParameters(null) directly, or calling setRequestBody(Object body)/setRequestBody(String) on a GenericMethod where the body is null and the method routes to addParameters for form-encoded bodies.","commonSituations":"Building form POST requests where the parameters map/array was never populated (e.g. a form with no fields), refactoring code that used to pass an empty array, deserializing request specs where parameters are optional and null is passed straight through.","solutions":["Pass an empty NameValuePair[] instead of null if you intend to clear/initialize form parameters.","Null-check or default your parameters collection before calling addParameters.","If a null body is expected, skip the addParameters call entirely and set the body explicitly."],"exampleFix":"// before\nmethod.addParameters(params); // params may be null\n// after\nif (params != null) {\n    method.addParameters(params);\n}","handlingStrategy":"validation","validationCode":"if (parameters == null) {\n    parameters = new NameValuePair[0];\n}\nmethod.addParameters(parameters);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Initialize parameter collections eagerly (empty, not null).","Centralize request building in one helper that normalizes null to empty arrays.","Enable trace logging on org.parosproxy.paros.network when debugging request bodies."],"tags":["http","request-body","null-argument"],"backgroundTag":"null-argument-ignored","analyzedSha":"9d1970a436b1b189bfb588fc88864c80d9baf6a5","analyzedAt":"2026-09-05T19:26:59.356Z","contentChangedAt":"2026-09-05T19:26:59.356Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}