elastic/elasticsearch · error · IllegalArgumentException

Unable to parse number of bytes from [${totalMemoryBytesOpti

Error message

Unable to parse number of bytes from [${totalMemoryBytesOption}]

What it means

Thrown by OverridableSystemMemoryInfo.availableSystemMemory() when the value after -Des.total_memory_bytes= cannot be parsed as a long (NumberFormatException). The override expects a plain decimal byte count.

Source

Thrown at distribution/tools/server-cli/src/main/java/org/elasticsearch/server/cli/OverridableSystemMemoryInfo.java:43

    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

  1. Provide the value as a plain integer number of bytes: -Des.total_memory_bytes=8589934592.
  2. Do not append unit suffixes (g/m/k) — the parser uses Long.parseLong.
  3. Strip any whitespace/quotes around the value.

Example fix

# before
ES_JAVA_OPTS="-Des.total_memory_bytes=8g"

# after (raw bytes)
ES_JAVA_OPTS="-Des.total_memory_bytes=8589934592"
Defensive patterns

Strategy: validation

Validate before calling

for (String o : userDefinedJvmOptions) {
    if (o.startsWith("-Des.total_memory_bytes=")) {
        String raw = o.split("=", 2)[1];
        if (!raw.matches("\\d+")) {
            throw new IllegalArgumentException("total_memory_bytes must be a plain decimal: " + o);
        }
    }
}

Prevention

When it happens

Trigger: Setting -Des.total_memory_bytes to a non-numeric string, a value with units (e.g. '8g'), or with stray characters.

Common situations: Passing '8g' or '8192m' instead of raw bytes; trailing whitespace; copy-paste from a doc that used units; locale-specific number formatting (comma separators).

Understand the failure class

Related errors


AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12). Data as JSON: /api/errors/3f855b70fc18861d. Report an issue: GitHub.