{"record":{"id":"8a9ac9960c3612f7","repo":"elastic/elasticsearch","slug":"negative-memory-size-specified-in-option","errorCode":null,"errorMessage":"Negative memory size specified in [{option}]","messagePattern":"Negative memory size specified in \\[(.+?)\\]","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"distribution/tools/server-cli/src/main/java/org/elasticsearch/server/cli/OverridableSystemMemoryInfo.java","lineNumber":39,"sourceCode":"\n    private final List<String> userDefinedJvmOptions;\n    private final SystemMemoryInfo fallbackSystemMemoryInfo;\n\n    public OverridableSystemMemoryInfo(final List<String> userDefinedJvmOptions, SystemMemoryInfo fallbackSystemMemoryInfo) {\n        this.userDefinedJvmOptions = Objects.requireNonNull(userDefinedJvmOptions);\n        this.fallbackSystemMemoryInfo = Objects.requireNonNull(fallbackSystemMemoryInfo);\n    }\n\n    @Override\n    public long availableSystemMemory() {\n\n        return userDefinedJvmOptions.stream()\n            .filter(option -> option.startsWith(\"-Des.total_memory_bytes=\"))\n            .map(totalMemoryBytesOption -> {\n                try {\n                    long bytes = Long.parseLong(totalMemoryBytesOption.split(\"=\", 2)[1]);\n                    if (bytes < 0) {\n                        throw new IllegalArgumentException(\"Negative memory size specified in [\" + totalMemoryBytesOption + \"]\");\n                    }\n                    return bytes;\n                } catch (NumberFormatException e) {\n                    throw new IllegalArgumentException(\"Unable to parse number of bytes from [\" + totalMemoryBytesOption + \"]\", e);\n                }\n            })\n            .reduce((previous, current) -> current) // this is effectively findLast(), so that ES_JAVA_OPTS overrides jvm.options\n            .orElse(fallbackSystemMemoryInfo.availableSystemMemory());\n    }\n}\n","sourceCodeStart":21,"sourceCodeEnd":50,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/distribution/tools/server-cli/src/main/java/org/elasticsearch/server/cli/OverridableSystemMemoryInfo.java#L21-L50","documentation":"Thrown by OverridableSystemMemoryInfo.availableSystemMemory() when the -Des.total_memory_bytes system property is set to a negative long. This property overrides ES's detected system memory for heap sizing; a negative value is nonsensical.","triggerScenarios":"Passing -Des.total_memory_bytes=-1 (or any negative number) via ES_JAVA_OPTS or jvm.options.","commonSituations":"Typo when overriding memory for testing; a script computing the value that underflows to negative; misunderstanding the unit (bytes, not MB/GB).","solutions":["Set -Des.total_memory_bytes to a positive value in bytes (e.g. 8589934592 for 8 GiB).","If you do not need the override, remove the -Des.total_memory_bytes entry entirely and let ES auto-detect.","Double-check any script/template that computes the value for arithmetic bugs."],"exampleFix":"# ES_JAVA_OPTS — before\nES_JAVA_OPTS=\"-Des.total_memory_bytes=-8589934592\"\n\n# after\nES_JAVA_OPTS=\"-Des.total_memory_bytes=8589934592\"","handlingStrategy":"validation","validationCode":"userDefinedJvmOptions.stream()\n    .filter(o -> o.startsWith(\"-Des.total_memory_bytes=\"))\n    .forEach(o -> {\n        long v = Long.parseLong(o.split(\"=\", 2)[1]);\n        if (v < 0) throw new IllegalArgumentException(\"total_memory_bytes must be >= 0: \" + o);\n    });","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only set -Des.total_memory_bytes to a positive byte count.","Prefer letting ES auto-detect system memory unless overriding for tests.","Check arithmetic in scripts that compute the value."],"tags":["jvm","memory","heap","config"],"backgroundTag":null,"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}