{"record":{"id":"153125ad986d9de0","repo":"elastic/elasticsearch","slug":"number-of-nodes-should-be-1-but-was-for","errorCode":null,"errorMessage":"Number of nodes should be >= 1 but was {} for {}","messagePattern":"Number of nodes should be >= 1 but was (.+?) for (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"build-tools/src/main/java/org/elasticsearch/gradle/testclusters/ElasticsearchCluster.java","lineNumber":173,"sourceCode":"        this.shared = shared;\n    }\n\n    @Classpath\n    public FileCollection getInstalledClasspath() {\n        return pluginAndModuleConfiguration.getAsFileTree().filter(f -> f.getName().endsWith(\".jar\"));\n    }\n\n    @InputFiles\n    @PathSensitive(PathSensitivity.RELATIVE)\n    public FileCollection getInstalledFiles() {\n        return pluginAndModuleConfiguration.getAsFileTree().filter(f -> f.getName().endsWith(\".jar\") == false);\n    }\n\n    public void setNumberOfNodes(int numberOfNodes) {\n        checkFrozen();\n\n        if (numberOfNodes < 1) {\n            throw new IllegalArgumentException(\"Number of nodes should be >= 1 but was \" + numberOfNodes + \" for \" + this);\n        }\n\n        if (numberOfNodes < nodes.size()) {\n            throw new IllegalArgumentException(\n                \"Cannot shrink \" + this + \" to have \" + numberOfNodes + \" nodes as it already has \" + getNumberOfNodes()\n            );\n        }\n\n        for (int i = nodes.size(); i < numberOfNodes; i++) {\n            this.nodes.add(\n                new ElasticsearchNode(\n                    safeName(clusterName),\n                    path,\n                    clusterName + \"-\" + i,\n                    project,\n                    reaper,\n                    testClustersRegistryProvider,\n                    fileSystemOperations,","sourceCodeStart":155,"sourceCodeEnd":191,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/build-tools/src/main/java/org/elasticsearch/gradle/testclusters/ElasticsearchCluster.java#L155-L191","documentation":"Thrown by ElasticsearchCluster.setNumberOfNodes when the requested node count is less than 1. A test cluster must have at least one node, so the guard rejects zero or negative inputs before mutating the node list.","triggerScenarios":"Calling setNumberOfNodes(0) or setNumberOfNodes(-n) on an ElasticsearchCluster (the Gradle test-cluster DSL), or wiring numberOfNodes from a property that resolves to <=0.","commonSituations":"Reading numberOfNodes from a -Ptest.numNodes flag or env var that defaults to 0 when unset; parameterizing tests with a node-count expression that underflows; copy-paste of a config block missing the count.","solutions":["Pass a positive integer: setNumberOfNodes(3) or numberOfNodes = 3 in the testClusters DSL.","If the value comes from a property, coerce and validate it: `Math.max(1, (project.findProperty('numNodes') ?: '1') as int)`.","Check the calling Gradle DSL block (testClusters { node {}) — make sure numberOfNodes is set, not left at 0."],"exampleFix":"// before\ntestClusters {\n  numberOfNodes = (project.findProperty('numNodes') ?: 0) as int\n}\n\n// after\ntestClusters {\n  numberOfNodes = Math.max(1, (project.findProperty('numNodes') ?: '1') as int)\n}","handlingStrategy":"validation","validationCode":"int n = requestedNodeCount;\nif (n < 1) {\n    throw new IllegalArgumentException(\"numberOfNodes must be >= 1, got \" + n);\n}\ncluster.setNumberOfNodes(n);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Coerce user-supplied node counts with Math.max(1, value).","Default test cluster size flags to a positive integer (e.g. '1').","Validate parameters at the point of input, not deep in the build."],"tags":["test","testclusters","configuration","validation"],"backgroundTag":null,"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}