{"record":{"id":"74ee161360013b98","repo":"apache/pulsar","slug":"window-length-for-time-and-count-are-set-please-s","errorCode":null,"errorMessage":"Window length for time and count are set! Please set one or the other.","messagePattern":"Window length for time and count are set! Please set one or the other\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/WindowConfigUtils.java","lineNumber":34,"sourceCode":" * specific language governing permissions and limitations\n * under the License.\n */\npackage org.apache.pulsar.functions.utils;\n\nimport org.apache.pulsar.common.functions.WindowConfig;\n\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) {","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/WindowConfigUtils.java#L16-L52","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Remove one of the two settings — keep windowLengthDurationMs for time-based windows or windowLengthCount for count-based windows, not both.","If merging configs, explicitly null out the field you don't want before validating.","Audit CLI flags and config files so only one window-length style is supplied."],"exampleFix":"// before\nconfig.setWindowLengthCount(100);\nconfig.setWindowLengthDurationMs(10_000L);\n// after\nconfig.setWindowLengthDurationMs(10_000L); // count removed","handlingStrategy":"validation","validationCode":"static void allowOnlyOneWindowLength(WindowConfig wc) {\n    if (wc.getWindowLengthDurationMs() != null && wc.getWindowLengthCount() != null) {\n        throw new IllegalArgumentException(\"Set only one of windowLengthDurationMs or windowLengthCount\");\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    WindowConfigUtils.validate(windowConfig);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"Window length for time and count are set\")) {\n        windowConfig.setWindowLengthCount(null); // prefer time-based, then retry\n        WindowConfigUtils.validate(windowConfig);\n        return;\n    }\n    throw e;\n}","preventionTips":["When switching between time- and count-based windows, explicitly null the abandoned field.","Centralize window config construction in one factory method that enforces exclusivity.","Check CLI flag defaults do not inject a value your config file also sets."],"tags":["java","pulsar-functions","windowing","configuration"],"backgroundTag":"conflicting-config","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"}