apache/pulsar · error · IllegalArgumentException
Window length must be positive [${windowLengthDurationMs}]
Error message
Window length must be positive [${windowLengthDurationMs}] What it means
Window-function config validation in WindowConfigUtils.validate: a time-based window length (windowLengthDurationMs set alone) was given as zero or negative milliseconds, which cannot define a valid tumbling window; the windowLengthDurationMs value is the faulty input.
Source
Thrown at pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/WindowConfigUtils.java:47
if (windowConfig.getWindowLengthDurationMs() == null && windowConfig.getWindowLengthCount() == null) {
throw new IllegalArgumentException("Window length is not specified");
}
if (windowConfig.getWindowLengthDurationMs() != null && windowConfig.getWindowLengthCount() != null) {
throw new IllegalArgumentException(
"Window length for time and count are set! Please set one or the other.");
}
if (windowConfig.getWindowLengthCount() != null) {
if (windowConfig.getWindowLengthCount() <= 0) {
throw new IllegalArgumentException(
"Window length must be positive [" + windowConfig.getWindowLengthCount() + "]");
}
}
if (windowConfig.getWindowLengthDurationMs() != null) {
if (windowConfig.getWindowLengthDurationMs() <= 0) {
throw new IllegalArgumentException(
"Window length must be positive [" + windowConfig.getWindowLengthDurationMs() + "]");
}
}
if (windowConfig.getSlidingIntervalCount() != null) {
if (windowConfig.getSlidingIntervalCount() <= 0) {
throw new IllegalArgumentException(
"Sliding interval must be positive [" + windowConfig.getSlidingIntervalCount() + "]");
}
}
if (windowConfig.getSlidingIntervalDurationMs() != null) {
if (windowConfig.getSlidingIntervalDurationMs() <= 0) {
throw new IllegalArgumentException(
"Sliding interval must be positive [" + windowConfig.getSlidingIntervalDurationMs() + "]");
}
}
View on GitHub (pinned to 820761864e)
Solutions
- Set windowLengthDurationMs to a positive value in milliseconds
Example fix
// before config.setWindowLengthDurationMs(0L); // after config.setWindowLengthDurationMs(60_000L); // 1 minute
Defensive patterns
Strategy: validation
Validate before calling
static void requirePositiveWindowDuration(WindowConfig wc) {
if (wc.getWindowLengthDurationMs() != null && wc.getWindowLengthDurationMs() <= 0) {
throw new IllegalArgumentException("windowLengthDurationMs must be > 0, got " + wc.getWindowLengthDurationMs());
}
} Type guard
static boolean isValidWindowDurationMs(Long durationMs) {
return durationMs != null && durationMs > 0;
} Try / catch
try {
WindowConfigUtils.validate(windowConfig);
} catch (IllegalArgumentException e) {
if (e.getMessage() != null && e.getMessage().startsWith("Window length must be positive")) {
throw new IllegalStateException("Fix window length settings: duration must be a positive number of ms", e);
}
throw e;
} Prevention
- To use defaults, omit the duration field instead of setting it to 0.
- Double-check unit conversions (seconds vs milliseconds) so values never collapse to 0.
- Clamp computed durations with Math.max(1, durationMs) before validation.
When it happens
Trigger: Calling WindowConfigUtils.validate(windowConfig) where getWindowLengthDurationMs() != null and getWindowLengthDurationMs() <= 0 — e.g. setWindowLengthDurationMs(0L), a duration parsed from "0" or an empty unit conversion, or a negative value from subtraction-based logic.
Common situations: Duration computed from (end - start) that evaluated to 0; config placeholders left as 0; unit conversion mistakes (e.g. ms vs seconds producing 0); user entering "0" intending 'use default'.
Understand the failure class
Background: "Invalid configuration value" and "Unsupported/Unknown setting value" errors: why libraries reject your config strings, numbers, and types — this error's family across 30 libraries.
Related errors
- Window length is not specified
- Window length for time and count are set! Please set one or
- Window length must be positive [${windowLengthCount}]
- Inconsistent types found between function input type and tim
- Not implemented
AI-assisted analysis of apache/pulsar@820761864e (2026-09-06).
Data as JSON: /api/errors/044c5f3bcadf4301.
Report an issue: GitHub.