{"record":{"id":"9c1290536731a820","repo":"apache/beam","slug":"slidingwindows-windowingstrategies-must-have-0-offset-period","errorCode":null,"errorMessage":"SlidingWindows WindowingStrategies must have 0 <= offset < period and 0 < size","messagePattern":"SlidingWindows WindowingStrategies must have 0 <= offset < period and 0 < size","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/windowing/SlidingWindows.java","lineNumber":90,"sourceCode":"  public SlidingWindows every(Duration period) {\n    return new SlidingWindows(period, size, offset);\n  }\n\n  /**\n   * Assigns timestamps into half-open intervals of the form [N * period + offset, N * period +\n   * offset + size).\n   *\n   * @throws IllegalArgumentException if offset is not in [0, period)\n   */\n  public SlidingWindows withOffset(Duration offset) {\n    return new SlidingWindows(period, size, offset);\n  }\n\n  private SlidingWindows(Duration period, Duration size, Duration offset) {\n    if (offset.isShorterThan(Duration.ZERO)\n        || !offset.isShorterThan(period)\n        || !size.isLongerThan(Duration.ZERO)) {\n      throw new IllegalArgumentException(\n          \"SlidingWindows WindowingStrategies must have 0 <= offset < period and 0 < size\");\n    }\n    this.period = period;\n    this.size = size;\n    this.offset = offset;\n  }\n\n  @Override\n  public Coder<IntervalWindow> windowCoder() {\n    return IntervalWindow.getCoder();\n  }\n\n  @Override\n  public Collection<IntervalWindow> assignWindows(AssignContext c) {\n    return assignWindows(c.timestamp());\n  }\n\n  public Collection<IntervalWindow> assignWindows(Instant timestamp) {","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/windowing/SlidingWindows.java#L72-L108","documentation":"SlidingWindows requires the constructor arguments to satisfy: offset >= 0, offset < period, and size > 0 (and separately period >= size elsewhere). The private SlidingWindows constructor validates these and throws IllegalArgumentException when violated, because such a windowing strategy is mathematically undefined.","triggerScenarios":"Calling SlidingWindows.of(size).every(period) with a negative offset, offset >= period, or a non-positive size — e.g. SlidingWindows.of(Duration.ZERO) or every(Duration.standardMinutes(10)) with an offset of 15 minutes on a 10-minute period.","commonSituations":"Config-driven window sizes where a YAML/JSON value of 0 or negative slipped through; computing period/offset from unit conversions that produced zero; copy-paste swapping size and period arguments.","solutions":["Ensure size > 0 before calling SlidingWindows.of(size)","Ensure offset < period and offset >= 0 when calling .every(period, offset)","Validate durations loaded from configuration before constructing the windowing","Swap arguments if size and period were accidentally reversed"],"exampleFix":"// before\nSlidingWindows.of(Duration.ZERO).every(Duration.standardMinutes(5)) // throws\n// after\nif (size.isLongerThan(Duration.ZERO) && offset.isShorterThan(period)) {\n  SlidingWindows.of(size).every(period, offset);\n}","handlingStrategy":"validation","validationCode":"static SlidingWindows safeSliding(Duration size, Duration period, Duration offset) {\n  if (size.isShorterThan(Duration.ONE_MILLISECOND) || offset.isShorterThan(Duration.ZERO) || !offset.isShorterThan(period))\n    throw new IllegalArgumentException(\"require size>0, 0<=offset<period\");\n  return SlidingWindows.of(size).every(period, offset);\n}","typeGuard":"boolean validSliding(Duration size, Duration period, Duration offset) { return size.isLongerThan(Duration.ZERO) && !offset.isShorterThan(Duration.ZERO) && offset.isShorterThan(period); }","tryCatchPattern":"try { return SlidingWindows.of(size).every(period, offset); } catch (IllegalArgumentException e) { LOG.error(\"Bad sliding window params size={} period={} offset={}\", size, period, offset, e); throw e; }","preventionTips":["Validate duration config values (>0) before constructing windowing","Do not swap size and period arguments","Add unit tests for boundary values (offset=0, offset=period, size=0)"],"tags":["java","apache-beam","windowing","argument-validation"],"backgroundTag":"value-out-of-range","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}