{"record":{"id":"044c5f3bcadf4301","repo":"apache/pulsar","slug":"window-length-must-be-positive-windowlengthdura","errorCode":null,"errorMessage":"Window length must be positive [${windowLengthDurationMs}]","messagePattern":"Window length must be positive \\[(.+?)\\]","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/WindowConfigUtils.java","lineNumber":47,"sourceCode":"        if (windowConfig.getWindowLengthDurationMs() == null && windowConfig.getWindowLengthCount() == null) {\n            throw new IllegalArgumentException(\"Window length is not specified\");\n        }\n\n        if (windowConfig.getWindowLengthDurationMs() != null && windowConfig.getWindowLengthCount() != null) {\n            throw new IllegalArgumentException(\n                    \"Window length for time and count are set! Please set one or the other.\");\n        }\n\n        if (windowConfig.getWindowLengthCount() != null) {\n            if (windowConfig.getWindowLengthCount() <= 0) {\n                throw new IllegalArgumentException(\n                        \"Window length must be positive [\" + windowConfig.getWindowLengthCount() + \"]\");\n            }\n        }\n\n        if (windowConfig.getWindowLengthDurationMs() != null) {\n            if (windowConfig.getWindowLengthDurationMs() <= 0) {\n                throw new IllegalArgumentException(\n                        \"Window length must be positive [\" + windowConfig.getWindowLengthDurationMs() + \"]\");\n            }\n        }\n\n        if (windowConfig.getSlidingIntervalCount() != null) {\n            if (windowConfig.getSlidingIntervalCount() <= 0) {\n                throw new IllegalArgumentException(\n                        \"Sliding interval must be positive [\" + windowConfig.getSlidingIntervalCount() + \"]\");\n            }\n        }\n\n        if (windowConfig.getSlidingIntervalDurationMs() != null) {\n            if (windowConfig.getSlidingIntervalDurationMs() <= 0) {\n                throw new IllegalArgumentException(\n                        \"Sliding interval must be positive [\" + windowConfig.getSlidingIntervalDurationMs() + \"]\");\n            }\n        }\n","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/WindowConfigUtils.java#L29-L65","documentation":"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.","triggerScenarios":"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.","commonSituations":"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'.","solutions":["Set windowLengthDurationMs to a positive value in milliseconds"],"exampleFix":"// before\nconfig.setWindowLengthDurationMs(0L);\n// after\nconfig.setWindowLengthDurationMs(60_000L); // 1 minute","handlingStrategy":"validation","validationCode":"static void requirePositiveWindowDuration(WindowConfig wc) {\n    if (wc.getWindowLengthDurationMs() != null && wc.getWindowLengthDurationMs() <= 0) {\n        throw new IllegalArgumentException(\"windowLengthDurationMs must be > 0, got \" + wc.getWindowLengthDurationMs());\n    }\n}","typeGuard":"static boolean isValidWindowDurationMs(Long durationMs) {\n    return durationMs != null && durationMs > 0;\n}","tryCatchPattern":"try {\n    WindowConfigUtils.validate(windowConfig);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"Window length must be positive\")) {\n        throw new IllegalStateException(\"Fix window length settings: duration must be a positive number of ms\", e);\n    }\n    throw e;\n}","preventionTips":["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."],"tags":["java","pulsar-functions","windowing","configuration"],"backgroundTag":"invalid-configuration-value","analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}