{"record":{"id":"e3141ef87d4a1342","repo":"elastic/elasticsearch","slug":"nodes-must-not-be-null-or-empty-e3141e","errorCode":null,"errorMessage":"nodes must not be null or empty","messagePattern":"nodes must not be null or empty","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"client/rest/src/main/java/org/elasticsearch/client/RestClientBuilder.java","lineNumber":136,"sourceCode":"        META_HEADER_VALUE = \"es=\"\n            + metaVersion\n            + \",jv=\"\n            + System.getProperty(\"java.specification.version\")\n            + \",t=\"\n            + metaVersion\n            + \",hc=\"\n            + (httpClientVersion == null ? \"\" : httpClientVersion.getRelease())\n            + LanguageRuntimeVersions.getRuntimeMetadata();\n    }\n\n    /**\n     * Creates a new builder instance and sets the hosts that the client will send requests to.\n     *\n     * @throws IllegalArgumentException if {@code nodes} is {@code null} or empty.\n     */\n    RestClientBuilder(List<Node> nodes) {\n        if (nodes == null || nodes.isEmpty()) {\n            throw new IllegalArgumentException(\"nodes must not be null or empty\");\n        }\n        for (Node node : nodes) {\n            if (node == null) {\n                throw new IllegalArgumentException(\"node cannot be null\");\n            }\n        }\n        this.nodes = nodes;\n    }\n\n    /**\n     * Sets the default request headers, which will be sent along with each request.\n     * <p>\n     * Request-time headers will always overwrite any default headers.\n     *\n     * @throws NullPointerException if {@code defaultHeaders} or any header is {@code null}.\n     */\n    public RestClientBuilder setDefaultHeaders(Header[] defaultHeaders) {\n        Objects.requireNonNull(defaultHeaders, \"defaultHeaders must not be null\");","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/client/rest/src/main/java/org/elasticsearch/client/RestClientBuilder.java#L118-L154","documentation":"Constructor guard on RestClientBuilder: the host list passed to HttpHost.create / RestClient.builder(...) must be non-null and contain at least one entry. An empty/null list is rejected immediately because the client has nowhere to send requests.","triggerScenarios":"Calling RestClient.builder() with no vararg hosts, or builder(List) with an empty list; programmatically building the list from config that resolved to nothing.","commonSituations":"Configuration source returned zero hosts (empty env var, blank 'ES_HOSTS'); list built by filtering that excluded all entries; mis-ordered builder steps.","solutions":["Validate your host source before calling RestClient.builder and fail fast with a clear config error.","Provide at least one HttpHost: RestClient.builder(new HttpHost(\"localhost\", 9200)).","Check the env var / property supplying hosts is non-empty."],"exampleFix":"// before\nList<HttpHost> hosts = loadFromConfig(); // returned []\nRestClient.builder(hosts.toArray(new HttpHost[0]));\n// after\nList<HttpHost> hosts = loadFromConfig();\nif (hosts.isEmpty()) throw new IllegalStateException(\"no ES hosts configured\");\nRestClient.builder(hosts.toArray(new HttpHost[0]));","handlingStrategy":"validation","validationCode":"if (hosts == null || hosts.isEmpty()) throw new IllegalArgumentException(\"configure at least one ES host\");\nRestClient.builder(hosts.toArray(new HttpHost[0]));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate config-derived host lists at startup, fail fast with a domain error.","Treat empty hosts as a deployment misconfiguration, not a runtime surprise."],"tags":["rest-client","builder","configuration","validation"],"backgroundTag":null,"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}