{"record":{"id":"9e858c39187a9ca4","repo":"apache/beam","slug":"tried-to-merge-a-non-existent-window","errorCode":null,"errorMessage":"Tried to merge a non-existent window:","messagePattern":"Tried to merge a non-existent window:","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/testing/WindowFnTestUtils.java","lineNumber":182,"sourceCode":"\n    private Map<W, Set<V>> elements = new HashMap<>();\n\n    public void put(W window, V value) {\n      Set<V> all = elements.computeIfAbsent(window, k -> new HashSet<>());\n      all.add(value);\n    }\n\n    public void merge(Collection<W> otherWindows, W window) {\n      if (otherWindows.isEmpty()) {\n        return;\n      }\n      Set<V> merged = new HashSet<>();\n      if (elements.containsKey(window) && !otherWindows.contains(window)) {\n        merged.addAll(elements.get(window));\n      }\n      for (W w : otherWindows) {\n        if (!elements.containsKey(w)) {\n          throw new IllegalArgumentException(\"Tried to merge a non-existent window:\" + w);\n        }\n        merged.addAll(elements.get(w));\n        elements.remove(w);\n      }\n      elements.put(window, merged);\n    }\n\n    public Collection<W> windows() {\n      return elements.keySet();\n    }\n\n    // For testing.\n\n    public Set<V> get(W window) {\n      return elements.get(window);\n    }\n  }\n","sourceCodeStart":164,"sourceCodeEnd":200,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/testing/WindowFnTestUtils.java#L164-L200","documentation":"WindowFnTestUtils.runWindowFunction/merge helper throws IllegalArgumentException when merging windows references a window that was never assigned any elements in the test's window-to-elements map. The utility requires every merged window to have a prior entry.","triggerScenarios":"Calling WindowFnTestUtils validate/merge helpers with a set of otherWindows where at least one window W is not a key in the elements map built from assignWindows results.","commonSituations":"Writing unit tests for a custom WindowFn where the expected merge set includes a window the WindowFn never actually assigned, or elements were not registered for all windows.","solutions":["Ensure every window passed to the merge call appears in the assignWindows output (add elements for it)","Fix the expected window set in the test to match what the WindowFn produces","Verify windows are constructed identically (same IntervalWindow bounds) as those returned by assignWindows"],"exampleFix":"// before\nrunWindowFunction(new IntervalWindow(0, 10), Arrays.asList(new IntervalWindow(20, 30))) // (20,30) has no elements\n// after\nassign elements to (20,30) via assignWindows first, or pass only windows present in the map","handlingStrategy":"validation","validationCode":"List<W> assigned = windowFn.assignWindows(...);\nif (!assigned.containsAll(expectedMergeWindows)) {\n  throw new AssertionError(\"expected windows not assigned: \" + expectedMergeWindows);\n}","typeGuard":null,"tryCatchPattern":"try { WindowFnTestUtils.runWindowFunction(...); }\ncatch (IllegalArgumentException e) {\n  if (e.getMessage().startsWith(\"Tried to merge a non-existent window\")) { /* fix expected window set */ }\n  throw e;\n}","preventionTips":["Only pass windows that appear in assignWindows output to merge checks","Compare windows with the exact same construction (IntervalWindow bounds) used by the WindowFn","Seed elements for every window involved in merging"],"tags":["java","testing","windows"],"backgroundTag":"resource-not-found","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"}