{"record":{"id":"87bf0569c4e0fede","repo":"apache/beam","slug":"exception-thrown-when-outputting-windowedvalue","errorCode":null,"errorMessage":"Exception thrown when outputting WindowedValue","messagePattern":"Exception thrown when outputting WindowedValue","errorType":"exception","errorClass":"java.lang.RuntimeException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/values/WindowedValues.java","lineNumber":262,"sourceCode":"    }\n\n    @Override\n    @Pure\n    public <OtherT> Builder<OtherT> withValue(OtherT newValue) {\n      // because of erasure, this type system lie is safe\n      return ((Builder<OtherT>) builder(this)).setValue(newValue);\n    }\n\n    @Override\n    public void output() {\n      try {\n        checkStateNotNull(receiver, \"A WindowedValueReceiver must be set via setReceiver()\")\n            .output(build());\n      } catch (Exception exc) {\n        if (exc instanceof RuntimeException) {\n          throw (RuntimeException) exc;\n        } else {\n          throw new RuntimeException(\"Exception thrown when outputting WindowedValue\", exc);\n        }\n      }\n    }\n\n    public WindowedValue<T> build() {\n      return WindowedValues.of(\n          getValue(),\n          getTimestamp(),\n          getWindows(),\n          getPaneInfo(),\n          getRecordId(),\n          getRecordOffset(),\n          causedByDrain(),\n          getOpenTelemetryContext(),\n          getValueKind());\n    }\n\n    @Override","sourceCodeStart":244,"sourceCodeEnd":280,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/values/WindowedValues.java#L244-L280","documentation":"WindowedValue.OutputWindowedValue.output() wraps any checked exception thrown by the receiver or the value builder into a RuntimeException with this message. Beam throws it because DoFn output delivery failed downstream (encoding, windowing, or receiver logic), and the original checked exception is preserved as the cause.","triggerScenarios":"Calling output() on a WindowedValue.OutputWindowedValue whose set value builder or receiver throws a checked Exception that is not a RuntimeException; typically the element's encoded form fails or the receiver's own logic throws IOException.","commonSituations":"A DoFn emitting a value whose Coder throws IOException during serialization; a custom WindowedValueReceiver throwing a checked exception; pipeline failures during bundle processing where the real cause is in the stack trace's 'Caused by'.","solutions":["Inspect the 'Caused by' chain to find the real underlying exception and fix it","Fix the Coder for the emitted value so encode() does not throw IOException","Ensure the receiver is set via setReceiver() before output() and does not throw checked exceptions","If the cause is a serializable-mismatch, verify the element type has a registered Coder"],"exampleFix":"// before: emit custom type without registered coder causing IOException downstream\ncontext.output(myCustomRecord);\n// after: register a Coder for the element type\npipeline.getCoderRegistry().registerCoderForClass(MyCustomRecord.class, MyCustomRecordCoder.of());","handlingStrategy":"try-catch","validationCode":"if (receiver == null) throw new IllegalStateException(\"call setReceiver() before output()\");","typeGuard":null,"tryCatchPattern":"try { outputWindowedValue.output(value); } catch (RuntimeException e) { Throwable cause = e.getCause(); log.error(\"WindowedValue output failed: {}\", cause != null ? cause.getMessage() : e.getMessage(), e); throw e; }","preventionTips":["Always call setReceiver() before output()","Ensure element types have registered, working Coders","Check the 'Caused by' chain rather than the wrapper message"],"tags":["java","beam","windowed-value","coder","runtime-exception"],"backgroundTag":"invalid-argument-value","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"}