{"record":{"id":"c747ccab8d0671ef","repo":"apache/beam","slug":"cannot-outputwithtimestamp-from-truncaterestriction","errorCode":null,"errorMessage":"Cannot outputWithTimestamp from TruncateRestriction","messagePattern":"Cannot outputWithTimestamp from TruncateRestriction","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"sdks/java/harness/src/main/java/org/apache/beam/fn/harness/SplittableTruncateSizedRestrictionsDoFnRunner.java","lineNumber":925,"sourceCode":"    @Override\n    @SuppressWarnings(\"nullness\")\n    public Object watermarkEstimatorState() {\n      return getCurrentWatermarkEstimatorState();\n    }\n\n    @Override\n    public RestrictionTracker<?, ?> restrictionTracker() {\n      return getCurrentTracker();\n    }\n\n    @Override\n    public PipelineOptions pipelineOptions() {\n      return pipelineOptions;\n    }\n\n    @Override\n    public void outputWithTimestamp(RestrictionT output, Instant timestamp) {\n      throw new UnsupportedOperationException(\n          \"Cannot outputWithTimestamp from TruncateRestriction\");\n    }\n\n    @Override\n    public void outputWindowedValue(\n        RestrictionT output,\n        Instant timestamp,\n        Collection<? extends BoundedWindow> windows,\n        PaneInfo paneInfo) {\n      throw new UnsupportedOperationException(\n          \"Cannot outputWindowedValue from TruncateRestriction\");\n    }\n  }\n\n  /**\n   * Passes split requests downstream, by way of trySplit on the overall runner, which will split\n   * per window if needed.\n   */","sourceCodeStart":907,"sourceCodeEnd":943,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/harness/src/main/java/org/apache/beam/fn/harness/SplittableTruncateSizedRestrictionsDoFnRunner.java#L907-L943","documentation":"The receiver provided to the @TruncateRestriction callback of a Splittable DoFn cannot emit elements with timestamps. TruncateRestriction only produces a replacement restriction when checkpointing/truncation occurs, so any element output is a model violation and throws UnsupportedOperationException.","triggerScenarios":"Calling outputWithTimestamp from inside a @TruncateRestriction method's OutputReceiver.","commonSituations":"Attempting to flush partial results during truncation/checkpoint; developers confusing truncateRestriction with processElement output semantics.","solutions":["Remove element output from @TruncateRestriction; only output a new restriction (or return nothing to signal no truncation).","Move result emission into @ProcessElement where the restriction tracker permits output.","If partial-result flushing is needed, use bundle finalization or state/timers instead."],"exampleFix":"// before\n@TruncateRestriction void truncate(@Restriction Restriction r, OutputReceiver<Restriction> out) { out.outputWithTimestamp(r, now); }\n// after\n@TruncateRestriction void truncate(@Restriction Restriction r, OutputReceiver<Restriction> out) { /* no output or out.output(newRestriction) */ }","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"boolean isTruncateRestrictionContext = ctx instanceof SplittableTruncateSizedRestrictionsDoFnRunner.TruncateRestrictionContext; // do not emit if true","tryCatchPattern":"try { out.outputWithTimestamp(r, ts); } catch (UnsupportedOperationException e) { LOG.error(\"Emitting from truncateRestriction is unsupported\"); }","preventionTips":["Never emit elements from @TruncateRestriction","Handle flushing of partial results in processElement/finalization","Review Splittable DoFn contract before adding output calls"],"tags":["apache-beam","splittable-dofn","unsupported-operation"],"backgroundTag":"unsupported-operation","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"}