elastic/elasticsearch · error · IllegalArgumentException
failed to parse [{}], fractional time values are not support
Error message
failed to parse [{}], fractional time values are not supported What it means
Thrown by TimeValue.parse when the numeric prefix of a time value fails Long.parseLong but succeeds as Double.parseDouble — i.e. the user supplied a fractional number. TimeValue stores durations as a long plus a TimeUnit, so fractional values are fundamentally unsupported. The original NumberFormatException is chained as the cause for diagnostics.
Source
Thrown at libs/core/src/main/java/org/elasticsearch/core/TimeValue.java:429
final String s = normalized.substring(0, normalized.length() - suffix.length()).trim();
try {
final long value = Long.parseLong(s);
if (value < -1) {
// -1 is magic, but reject any other negative values
throw new IllegalArgumentException(
"failed to parse setting ["
+ settingName
+ "] with value ["
+ initialInput
+ "] as a time value: negative durations are not supported"
);
}
return value;
} catch (final NumberFormatException e) {
try {
@SuppressWarnings("unused")
final double ignored = Double.parseDouble(s);
throw new IllegalArgumentException("failed to parse [" + initialInput + "], fractional time values are not supported", e);
} catch (final NumberFormatException ignored) {
throw new IllegalArgumentException("failed to parse [" + initialInput + "]", e);
}
}
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
return this.compareTo(((TimeValue) o)) == 0;
}
@Override
public int hashCode() {
return Double.hashCode(((double) duration) * timeUnit.toNanos(1));
}View on GitHub (pinned to db6a809a66)
Solutions
- Round or truncate to a whole number of the smallest needed unit, e.g. convert 1.5s to 1500ms.
- If the source is a double, scale and cast: long ms = (long) Math.round(seconds * 1000); then format ms + "ms".
- Replace the fractional literal in elasticsearch.yml or the settings API with an integer-equivalent duration.
- Validate user-supplied time strings with a regex like ^-?\d+[a-z]+$ before forwarding them to TimeValue.
Example fix
// before String t = "1.5s"; TimeValue.parseTimeValue(t, "x"); // after — scale to milliseconds String t = Math.round(1.5 * 1000) + "ms"; // "1500ms"
Defensive patterns
Strategy: validation
Validate before calling
// Reject fractional magnitudes before parsing
static String requireIntegralDuration(String s) {
String body = s.toLowerCase(Locale.ROOT).trim().replaceAll("(ns|us|micros|ms|s|m|h|d)$", "");
if (body.matches(".*[.e].*")) throw new IllegalArgumentException("fractional not allowed: " + s);
return s;
} Type guard
static boolean isIntegralTimeValue(String s) {
if (s == null) return false;
String n = s.trim().toLowerCase(Locale.ROOT);
return n.matches("-?\\d+(ns|us|micros|ms|s|m|h|d)") || n.equals("-1") || n.matches("0+");
} Try / catch
try {
TimeValue.parseTimeValue(raw, setting);
} catch (IllegalArgumentException e) {
if (e.getMessage().contains("fractional")) {
// rescale: parse the double, convert to smallest integer unit
} else {
throw e;
}
} Prevention
- Never concatenate a float/double into a time string; scale to an integral unit first.
- When accepting timeouts from JSON, type them as integer milliseconds or as ISO durations.
- In tests, fuzz time-value inputs to catch fractional edge cases.
- Document for API consumers that durations are integer + unit.
When it happens
Trigger: Passing a fractional duration string such as "1.5s", "0.5d", "2.25h", ".5ms" to any code path that calls TimeValue.parseTimeValue. Fires at TimeValue.java:429 in the inner try after Double.parseDouble(s) succeeds.
Common situations: Converting a float/double timeout (e.g. from a JSON payload or a metrics-derived value) directly to a string without rounding. Migrating configs from systems that accept fractional seconds (Python's timedelta, ISO-8601 durations). Tooling that does String.valueOf(2.5) + "s".
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- failed to parse setting [{}] with value [{}] as a time value
- failed to parse [{}]
- failed to parse setting [{}] with value [{}] as a time value
- Failed to parse value [{}] as only [true] or [false] are all
- duration cannot be negative, was given [{}]
AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12).
Data as JSON: /api/errors/ac7c5b201b1db93c.
Report an issue: GitHub.