{"record":{"id":"22d6f032012d99e3","repo":"elastic/elasticsearch","slug":"url-parameter-has-already-been-set-to","errorCode":null,"errorMessage":"url parameter [{}] has already been set to [{}]","messagePattern":"url parameter \\[(.+?)\\] has already been set to \\[(.+?)\\]","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"client/rest/src/main/java/org/elasticsearch/client/Request.java","lineNumber":78,"sourceCode":"    /**\n     * The path of the request (without scheme, host, port, or prefix).\n     */\n    public String getEndpoint() {\n        return endpoint;\n    }\n\n    /**\n     * Add a query string parameter.\n     * @param name the name of the url parameter. Must not be null.\n     * @param value the value of the url parameter. If {@code null} then\n     *      the parameter is sent as {@code name} rather than {@code name=value}\n     * @throws IllegalArgumentException if a parameter with that name has\n     *      already been set\n     */\n    public void addParameter(String name, String value) {\n        Objects.requireNonNull(name, \"url parameter name cannot be null\");\n        if (parameters.containsKey(name)) {\n            throw new IllegalArgumentException(\"url parameter [\" + name + \"] has already been set to [\" + parameters.get(name) + \"]\");\n        } else {\n            parameters.put(name, value);\n        }\n    }\n\n    public void addParameters(Map<String, String> paramSource) {\n        paramSource.forEach(this::addParameter);\n    }\n\n    /**\n     * Query string parameters. The returned map is an unmodifiable view of the\n     * map in the request so calls to {@link #addParameter(String, String)}\n     * will change it.\n     */\n    public Map<String, String> getParameters() {\n        return unmodifiableMap(parameters);\n    }\n","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/client/rest/src/main/java/org/elasticsearch/client/Request.java#L60-L96","documentation":"Request.addParameter stores query parameters in a map keyed by name and forbids overwriting an existing key, throwing with both the name and the previously-set value. Callers must deliberately set a parameter once; to change it they should build a fresh Request rather than mutate, preventing accidental double-application of filters/params.","triggerScenarios":"Calling req.addParameter(\"size\", \"10\") twice on the same Request instance; calling addParameters(map) where the map contains a key already added via addParameter; chaining helper builders that each set the same param (e.g. 'pretty', 'filter_path').","commonSituations":"A request builder helper sets 'filter_path' and the caller also sets it; merging two parameter maps that overlap; reusing a Request object across retries and re-adding params.","solutions":["Set each parameter at most once; remove the duplicate addParameter call.","If overriding is intended, construct a new Request and set the final value, or clear parameters first.","Centralize parameter setting in one builder method to avoid scattered duplicate calls."],"exampleFix":"// before\nreq.addParameter(\"size\", \"10\");\nreq.addParameter(\"size\", \"50\"); // throws\n// after\nreq.addParameter(\"size\", \"50\"); // set once","handlingStrategy":"validation","validationCode":"// Ensure a param is set exactly once per Request:\nif (!req.getParameters().containsKey(name)) {\n    req.addParameter(name, value);\n} else {\n    // build a fresh Request or log a conflict\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Centralize parameter setting in one builder method per request type.","Don't reuse Request objects across retries; rebuild fresh.","When merging parameter maps, dedupe by name first."],"tags":["rest-client","validation","request","query-params"],"backgroundTag":null,"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}