zhisheng17/flink-learning · error · IllegalArgumentException

The value '${text}' cannot be re represented as 64bit number

Error message

The value '${text}' cannot be re represented as 64bit number of bytes (numeric overflow).

What it means

After computing value * multiplier in parseDuration, TimeUtils verifies the result by dividing back; if the round-trip does not reproduce the original value, the multiplication overflowed 64 bits. It throws this IllegalArgumentException instead of silently returning a wrapped-around duration.

Source

Thrown at flink-learning-core/src/main/java/com/zhisheng/core/utils/TimeUtils.java:89

			if (matchTimeUnit(unit, TimeUnit.MILLISECONDS)) {
				multiplier = 1L;
			} else if (matchTimeUnit(unit, TimeUnit.SECONDS)) {
				multiplier = 1000L;
			} else if (matchTimeUnit(unit, TimeUnit.MINUTES)) {
				multiplier = 1000L * 60L;
			} else if (matchTimeUnit(unit, TimeUnit.HOURS)) {
				multiplier = 1000L * 60L * 60L;
			} else {
				throw new IllegalArgumentException("Time interval unit '" + unit +
					"' does not match any of the recognized units: " + TimeUnit.getAllUnits());
			}
		}

		final long result = value * multiplier;

		// check for overflow
		if (result / multiplier != value) {
			throw new IllegalArgumentException("The value '" + text +
				"' cannot be re represented as 64bit number of bytes (numeric overflow).");
		}

		return Duration.ofMillis(result);
	}

	private static boolean matchTimeUnit(String text, TimeUnit unit) {
		return text.equals(unit.getUnit());
	}

	/**
	 * Enum which defines time unit, mostly used to parse value from configuration file.
	 */
	private enum TimeUnit {
		MILLISECONDS("ms"),
		SECONDS("s"),
		MINUTES("min"),
		HOURS("h");

View on GitHub (pinned to d731cee761)

Solutions

  1. Reduce the numeric value in the duration string to a sane range (e.g. '2147483647 ms' max for typical use).
  2. Use a larger unit to express the same duration (e.g. '2147483648 s' instead of milliseconds).
  3. Pre-check the magnitude: if value > Long.MAX_VALUE / multiplierMillis, reject before calling parseDuration.
  4. Catch IllegalArgumentException and surface a validation error to the user.

Example fix

// before
Duration d = TimeUtils.parseDuration("99999999999999999999 s");
// after
long seconds = 99999999999999999999L > Long.MAX_VALUE / 1000 ? Long.MAX_VALUE / 1000 : 99999999999999999999L;
Duration d = Duration.ofSeconds(seconds);
Defensive patterns

Strategy: validation

Validate before calling

static void checkDurationMagnitude(String text, long multiplierMillis) {
    long value = Long.parseLong(text.trim().split("\\s+")[0]);
    if (value != 0 && value > Long.MAX_VALUE / multiplierMillis)
        throw new IllegalArgumentException("Duration " + text + " overflows long milliseconds");
}

Try / catch

try {
    d = TimeUtils.parseDuration(text);
} catch (IllegalArgumentException e) {
    d = Duration.ofMillis(Long.MAX_VALUE); // or fail fast with clear message
}

Prevention

When it happens

Trigger: Parsing an enormous duration value like '9223372036854775807 h' or any value whose product with the unit multiplier exceeds Long.MAX_VALUE.

Common situations: Misconfigured values where a raw timestamp or byte count was pasted into a duration field; accidental repeated digits in config; programmatically computed durations not clamped before parsing.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


AI-assisted analysis of zhisheng17/flink-learning@d731cee761 (2026-09-06). Data as JSON: /api/errors/57b3675c2b73efac. Report an issue: GitHub.