apache/pulsar · error · IllegalArgumentException

Window length for time and count are set! Please set one or

Error message

Window length for time and count are set! Please set one or the other.

What it means

Thrown by WindowConfigUtils.validate when both windowLengthDurationMs and windowLengthCount are set. Window length must be expressed either in time or in event count, not both; the validator rejects ambiguous configurations with this explicit message.

Source

Thrown at pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/WindowConfigUtils.java:34

 * specific language governing permissions and limitations
 * under the License.
 */
package org.apache.pulsar.functions.utils;

import org.apache.pulsar.common.functions.WindowConfig;

public class WindowConfigUtils {

    public static final long DEFAULT_MAX_LAG_MS = 0; // no lag
    public static final long DEFAULT_WATERMARK_EVENT_INTERVAL_MS = 1000; // 1s

    public static void validate(WindowConfig windowConfig) {
        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) {

View on GitHub (pinned to 820761864e)

Solutions

  1. Remove one of the two settings — keep windowLengthDurationMs for time-based windows or windowLengthCount for count-based windows, not both.
  2. If merging configs, explicitly null out the field you don't want before validating.
  3. Audit CLI flags and config files so only one window-length style is supplied.

Example fix

// before
config.setWindowLengthCount(100);
config.setWindowLengthDurationMs(10_000L);
// after
config.setWindowLengthDurationMs(10_000L); // count removed
Defensive patterns

Strategy: validation

Validate before calling

static void allowOnlyOneWindowLength(WindowConfig wc) {
    if (wc.getWindowLengthDurationMs() != null && wc.getWindowLengthCount() != null) {
        throw new IllegalArgumentException("Set only one of windowLengthDurationMs or windowLengthCount");
    }
}

Try / catch

try {
    WindowConfigUtils.validate(windowConfig);
} catch (IllegalArgumentException e) {
    if (e.getMessage() != null && e.getMessage().startsWith("Window length for time and count are set")) {
        windowConfig.setWindowLengthCount(null); // prefer time-based, then retry
        WindowConfigUtils.validate(windowConfig);
        return;
    }
    throw e;
}

Prevention

When it happens

Trigger: Calling WindowConfigUtils.validate(windowConfig) where both getWindowLengthDurationMs() != null and getWindowLengthCount() != null — e.g. setting both fields programmatically, or merging defaults/CLI flags that each supplied one of the two values.

Common situations: Config templating that fills in both keys; switching from count-based to time-based windows by adding duration without removing count; CLI flag defaults combined with explicit config file values; copy-pasted config blocks containing both settings.

Related errors


AI-assisted analysis of apache/pulsar@820761864e (2026-09-06). Data as JSON: /api/errors/74ee161360013b98. Report an issue: GitHub.