elastic/elasticsearch · error · IllegalArgumentException
Negative memory size specified in [{option}]
Error message
Negative memory size specified in [{option}] What it means
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.
Source
Thrown at distribution/tools/server-cli/src/main/java/org/elasticsearch/server/cli/OverridableSystemMemoryInfo.java:39
private final List<String> userDefinedJvmOptions;
private final SystemMemoryInfo fallbackSystemMemoryInfo;
public OverridableSystemMemoryInfo(final List<String> userDefinedJvmOptions, SystemMemoryInfo fallbackSystemMemoryInfo) {
this.userDefinedJvmOptions = Objects.requireNonNull(userDefinedJvmOptions);
this.fallbackSystemMemoryInfo = Objects.requireNonNull(fallbackSystemMemoryInfo);
}
@Override
public long availableSystemMemory() {
return userDefinedJvmOptions.stream()
.filter(option -> option.startsWith("-Des.total_memory_bytes="))
.map(totalMemoryBytesOption -> {
try {
long bytes = Long.parseLong(totalMemoryBytesOption.split("=", 2)[1]);
if (bytes < 0) {
throw new IllegalArgumentException("Negative memory size specified in [" + totalMemoryBytesOption + "]");
}
return bytes;
} catch (NumberFormatException e) {
throw new IllegalArgumentException("Unable to parse number of bytes from [" + totalMemoryBytesOption + "]", e);
}
})
.reduce((previous, current) -> current) // this is effectively findLast(), so that ES_JAVA_OPTS overrides jvm.options
.orElse(fallbackSystemMemoryInfo.availableSystemMemory());
}
}
View on GitHub (pinned to db6a809a66)
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.
Example fix
# ES_JAVA_OPTS — before ES_JAVA_OPTS="-Des.total_memory_bytes=-8589934592" # after ES_JAVA_OPTS="-Des.total_memory_bytes=8589934592"
Defensive patterns
Strategy: validation
Validate before calling
userDefinedJvmOptions.stream()
.filter(o -> o.startsWith("-Des.total_memory_bytes="))
.forEach(o -> {
long v = Long.parseLong(o.split("=", 2)[1]);
if (v < 0) throw new IllegalArgumentException("total_memory_bytes must be >= 0: " + o);
}); Prevention
- 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.
When it happens
Trigger: Passing -Des.total_memory_bytes=-1 (or any negative number) via ES_JAVA_OPTS or jvm.options.
Common situations: Typo when overriding memory for testing; a script computing the value that underflows to negative; misunderstanding the unit (bytes, not MB/GB).
Related errors
- Unable to parse number of bytes from [${totalMemoryBytesOpti
- Invalid jvm argument `{}` configure as systemProperty instea
- starting java failed with [%d] output: %s error: %s
- 78
- unexpected exception creating MessageDigest instance for [{}
AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12).
Data as JSON: /api/errors/8a9ac9960c3612f7.
Report an issue: GitHub.