{"record":{"id":"d357bc90c9f8fcc8","repo":"apache/beam","slug":"timestamp-unsupported-in-context","errorCode":null,"errorMessage":"Timestamp unsupported in ${context}","messagePattern":"Timestamp unsupported in (.+?)","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/reflect/DoFnInvoker.java","lineNumber":342,"sourceCode":"      throw new UnsupportedOperationException(\n          String.format(\"SideInput unsupported in %s\", getErrorContext()));\n    }\n\n    @Override\n    public TimerMap timerFamily(String tagId) {\n      throw new UnsupportedOperationException(\n          String.format(\"TimerFamily unsupported in %s\", getErrorContext()));\n    }\n\n    @Override\n    public @Nullable Object schemaElement(int index) {\n      throw new UnsupportedOperationException(\n          String.format(\"Schema element unsupported in %s\", getErrorContext()));\n    }\n\n    @Override\n    public Instant timestamp(DoFn<InputT, OutputT> doFn) {\n      throw new UnsupportedOperationException(\n          String.format(\"Timestamp unsupported in %s\", getErrorContext()));\n    }\n\n    @Override\n    public @Nullable String currentRecordId(DoFn<InputT, OutputT> doFn) {\n      throw new UnsupportedOperationException(\n          String.format(\"RecordId unsupported in %s\", getErrorContext()));\n    }\n\n    @Override\n    public @Nullable Long currentRecordOffset(DoFn<InputT, OutputT> doFn) {\n      throw new UnsupportedOperationException(\n          String.format(\"RecordOffset unsupported in %s\", getErrorContext()));\n    }\n\n    @Override\n    public Instant fireTimestamp(DoFn<InputT, OutputT> doFn) {\n      throw new UnsupportedOperationException(","sourceCodeStart":324,"sourceCodeEnd":360,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/reflect/DoFnInvoker.java#L324-L360","documentation":"This UnsupportedOperationException is thrown by DoFnInvoker.BaseArgumentProvider.timestamp when the element timestamp parameter is requested in a DoFn invocation context that has no input element. Only @ProcessElement (and similar element-processing contexts) carries a bounded input with a timestamp; contexts like @StartBundle or @FinishBundle leave timestamp un-overridden in the base provider, which always throws. getErrorContext() identifies the offending context in the message.","triggerScenarios":"Declaring an Instant timestamp parameter (or calling c.timestamp(doFn) / BoundedWindow-style accessors relying on it) in @StartBundle, @FinishBundle, @OnTimer (use fireTimestamp there), @OnWindowExpiration methods, or a custom ArgumentProvider that does not override timestamp(DoFn).","commonSituations":"Copy-pasting a @ProcessElement signature including the timestamp parameter into a @FinishBundle aggregation method; expecting to read the last element's timestamp in @FinishBundle; test harness ArgumentProviders that only override element() and outputReceiver().","solutions":["Request the timestamp parameter only in @ProcessElement; capture or aggregate timestamps into instance fields if they are needed later in @FinishBundle.","In @OnTimer methods, use the fireTimestamp parameter (Instant of the timer firing) rather than the element timestamp.","Remove the timestamp parameter from lifecycle methods entirely if no per-element value is meaningful there.","If implementing a custom ArgumentProvider, override timestamp(DoFn) to return the current element's timestamp."],"exampleFix":"// before\n@FinishBundle\npublic void finishBundle(FinishBundleContext c, Instant ts) { // throws\n  c.output(buildResult(), ts, window);\n}\n\n// after\nprivate Instant lastTs;\n\n@ProcessElement\npublic void processElement(ProcessContext c, Instant ts) {\n  lastTs = ts;\n}\n\n@FinishBundle\npublic void finishBundle(FinishBundleContext c) {\n  c.output(buildResult(), lastTs, window);\n}","handlingStrategy":"validation","validationCode":"// Element timestamp exists only in element-processing context; verify the method annotation.\n// Before adding an 'Instant ts' parameter, confirm the method is @ProcessElement (or use fireTimestamp in @OnTimer).","typeGuard":"if (context instanceof DoFn.ProcessContext) {\n  Instant ts = context.timestamp();\n}","tryCatchPattern":"try {\n  Instant ts = context.timestamp();\n} catch (UnsupportedOperationException e) {\n  // no element in this phase; use a stored timestamp or Instant.now()-based policy\n}","preventionTips":["Declare timestamp parameters only on @ProcessElement methods.","Use fireTimestamp for @OnTimer and explicit timestamps for @FinishBundle outputs stored earlier.","Cache needed per-element timestamps in instance fields for later lifecycle phases."],"tags":["apache-beam","java","unsupported-operation","timestamps","dofn"],"backgroundTag":"unsupported-operation","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}