{"record":{"id":"5e3aabb9fec5d5b3","repo":"apache/pulsar","slug":"window-length-is-not-specified","errorCode":null,"errorMessage":"Window length is not specified","messagePattern":"Window length is not specified","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/WindowConfigUtils.java","lineNumber":30,"sourceCode":" * Unless required by applicable law or agreed to in writing,\n * software distributed under the License is distributed on an\n * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n * KIND, either express or implied.  See the License for the\n * 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() + \"]\");","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/WindowConfigUtils.java#L12-L48","documentation":"Thrown by WindowConfigUtils.validate when a WindowConfig specifies neither windowLengthDurationMs nor windowLengthCount. A window function needs exactly one way to delimit window length (time-based or count-based); with both null the windowing runtime cannot compute window boundaries, so the config is rejected at submission time.","triggerScenarios":"Calling WindowConfigUtils.validate(windowConfig) (directly or via function config validation when configuring a windowed function) where both getWindowLengthDurationMs() and getWindowLengthCount() return null — e.g. building WindowConfig programmatically without setting either field, or a YAML/JSON config omitting both keys.","commonSituations":"Programmatically constructed WindowConfig with defaults left unset; window config parsed from a properties file where keys were misspelled so neither field got populated; upgrading configs where the window-length key name changed; enabling windowing with only slidingInterval settings, forgetting the length.","solutions":["Set exactly one of windowLengthDurationMs (time-based) or windowLengthCount (count-based) on the WindowConfig.","If configuring via CLI/JSON, provide --window-length-duration-ms or --window-length-count.","Check the config file/keys for misspellings that leave both fields null after parsing."],"exampleFix":"// before\nWindowConfig config = new WindowConfig(); // neither length set\n// after\nWindowConfig config = new WindowConfig();\nconfig.setWindowLengthDurationMs(10_000L); // or setWindowLengthCount(100)","handlingStrategy":"validation","validationCode":"static void requireWindowLength(WindowConfig wc) {\n    if (wc.getWindowLengthDurationMs() == null && wc.getWindowLengthCount() == null) {\n        throw new IllegalArgumentException(\n            \"windowConfig must set exactly one of windowLengthDurationMs or windowLengthCount before validation\");\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    WindowConfigUtils.validate(windowConfig);\n} catch (IllegalArgumentException e) {\n    if (\"Window length is not specified\".equals(e.getMessage())) {\n        windowConfig.setWindowLengthDurationMs(60_000L); // sane default, then retry\n        WindowConfigUtils.validate(windowConfig);\n        return;\n    }\n    throw e;\n}","preventionTips":["Always set exactly one of windowLengthDurationMs / windowLengthCount when enabling windowing.","Validate user-supplied window config keys before parsing into WindowConfig to catch misspellings.","Add a unit test asserting every shipped windowed-function config passes WindowConfigUtils.validate."],"tags":["java","pulsar-functions","windowing","configuration"],"backgroundTag":"missing-required-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"}