{"record":{"id":"13213c94ae151c5a","repo":"apache/pulsar","slug":"window-length-must-be-positive-windowlengthcoun","errorCode":null,"errorMessage":"Window length must be positive [${windowLengthCount}]","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":40,"sourceCode":"\npublic class WindowConfigUtils {\n\n    public static final long DEFAULT_MAX_LAG_MS = 0; // no lag\n    public static final long DEFAULT_WATERMARK_EVENT_INTERVAL_MS = 1000; // 1s\n\n    public static void validate(WindowConfig windowConfig) {\n        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","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/WindowConfigUtils.java#L22-L58","documentation":"Window-function config validation in WindowConfigUtils.validate: a count-based window length was supplied (windowLengthCount set alone) but its value is zero or negative, which cannot define a valid tumbling window; the windowLengthCount value is the faulty input.","triggerScenarios":"Calling WindowConfigUtils.validate(windowConfig) where getWindowLengthCount() != null and getWindowLengthCount() <= 0 — e.g. setWindowLengthCount(0), a negative value from a computed expression, or a zero default from a template.","commonSituations":"Building the count from an unvalidated property (parseInt of empty/0 string); math that computes the count as floor of something that can be 0; placeholder values left in config intending to be replaced later.","solutions":["Set windowLengthCount to a positive integer"],"exampleFix":"// before\nconfig.setWindowLengthCount(0);\n// after\nconfig.setWindowLengthCount(100);","handlingStrategy":"validation","validationCode":"static void requirePositiveWindowLengthCount(WindowConfig wc) {\n    if (wc.getWindowLengthCount() != null && wc.getWindowLengthCount() <= 0) {\n        throw new IllegalArgumentException(\"windowLengthCount must be >= 1, got \" + wc.getWindowLengthCount());\n    }\n}","typeGuard":"static boolean isValidWindowLengthCount(Integer count) {\n    return count != null && count > 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: count must be a positive integer\", e);\n    }\n    throw e;\n}","preventionTips":["Clamp computed counts with Math.max(1, count) before setting them.","Reject zero/empty numeric strings when parsing window config from properties.","Never leave 0 as a placeholder value in window configs."],"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-14T00:17:10.932Z"}