apache/beam · error · IllegalArgumentException
Could not encode provided windows with the provided window…
Error message
Could not encode provided windows with the provided window coder
What it means
WindowSupplier.of encodes each provided window with the supplied Coder; if any encoding fails (CoderException) it wraps it in this IllegalArgumentException. The provided coder cannot serialize one of the provided window instances.
Solutions
- Pass the coder matching the window type, e.g. IntervalWindow.getCoder() or WindowCoder.of()
- Verify the Iterable<W> windows actually match the Coder<W> type parameter
- Catch at authoring time by unit-testing encode/decode round-trip of one window
Example fix
// before WindowSupplier.of(InstantCoder.of(), windows) // wrong coder // after WindowSupplier.of(IntervalWindow.getCoder(), windows)
Defensive patterns
Strategy: validation
Validate before calling
for (W window : windows) {
CoderUtils.encodeToByteArray(coder, window); // throws CoderException early with better context
} Try / catch
try { WindowSupplier.of(coder, windows); }
catch (IllegalArgumentException e) { /* coder does not match window type; fix coder */ } Prevention
- Always derive the coder from the window type (e.g. IntervalWindow.getCoder())
- Round-trip encode/decode one window before constructing the supplier
- Keep Coder<W> generics aligned with the Iterable<W> element type
When it happens
Trigger: Calling WindowSupplier.of(coder, windows) with a coder incompatible with the window objects (wrong coder type, coder that throws CoderException for these values).
Common situations: Passing e.g. a GlobalWindow coder for IntervalWindow values, or a coder whose type parameters don't match the windows after a refactor.
Understand the failure class
Background: "is not a compatible type" / "cannot merge" errors: when a value's type doesn't match what the library requires — this error's family across 65 libraries.
Related errors
- Could not decode provided windows with the provided window…
- The input value cannot be encoded
- The input value cannot be encoded
- ApproximateUnique.PerKey requires its input to use KvCoder
- AvroCoder for GenericRecord requires a schema
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/9f28920dc12f9c5b.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/java/core/src/main/java/org/apache/beam/sdk/testing/WindowSupplier.java:55
// Spotbugs thinks synchronization is for the fields, but it is for the act of decoding
@SuppressFBWarnings("IS2_INCONSISTENT_SYNC")
@SuppressWarnings({
"nullness" // TODO(https://github.com/apache/beam/issues/20497)
})
final class WindowSupplier implements Supplier<Collection<BoundedWindow>>, Serializable {
private final Coder<? extends BoundedWindow> coder;
private final Collection<byte[]> encodedWindows;
/** Access via {@link #get()}. */
private transient @Nullable Collection<BoundedWindow> windows;
public static <W extends BoundedWindow> WindowSupplier of(Coder<W> coder, Iterable<W> windows) {
ImmutableSet.Builder<byte[]> windowsBuilder = ImmutableSet.builder();
for (W window : windows) {
try {
windowsBuilder.add(CoderUtils.encodeToByteArray(coder, window));
} catch (CoderException e) {
throw new IllegalArgumentException(
"Could not encode provided windows with the provided window coder", e);
}
}
return new WindowSupplier(coder, windowsBuilder.build());
}
private WindowSupplier(Coder<? extends BoundedWindow> coder, Collection<byte[]> encodedWindows) {
this.coder = coder;
this.encodedWindows = encodedWindows;
}
@Override
public Collection<BoundedWindow> get() {
if (windows == null) {
decodeWindows();
}
return windows;
}View on GitHub (pinned to 12126d8942)