{"record":{"id":"29fd18424b8d005c","repo":"apache/beam","slug":"not-expected-to-access-restrictiontracker-from-a-regular","errorCode":null,"errorMessage":"Not expected to access RestrictionTracker from a regular DoFn in DoFnTester","messagePattern":"Not expected to access RestrictionTracker from a regular DoFn in DoFnTester","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/DoFnTester.java","lineNumber":350,"sourceCode":"            public OutputReceiver<OutputT> outputReceiver(DoFn<InputT, OutputT> doFn) {\n              return DoFnOutputReceivers.windowedReceiver(processContext, builderSupplier, null);\n            }\n\n            @Override\n            public MultiOutputReceiver taggedOutputReceiver(DoFn<InputT, OutputT> doFn) {\n              return DoFnOutputReceivers.windowedMultiReceiver(\n                  processContext, builderSupplier, null);\n            }\n\n            @Override\n            public Object restriction() {\n              throw new UnsupportedOperationException(\n                  \"Not expected to access Restriction from a regular DoFn in DoFnTester\");\n            }\n\n            @Override\n            public RestrictionTracker<?, ?> restrictionTracker() {\n              throw new UnsupportedOperationException(\n                  \"Not expected to access RestrictionTracker from a regular DoFn in DoFnTester\");\n            }\n          });\n    } catch (UserCodeException e) {\n      unwrapUserCodeException(e);\n    }\n  }\n\n  /**\n   * @deprecated Use {@link TestPipeline} with the {@code DirectRunner}.\n   */\n  @Deprecated\n  public void finishBundle() throws Exception {\n    checkState(\n        state == State.BUNDLE_STARTED,\n        \"Must be inside bundle to call finishBundle, but was: %s\",\n        state);\n    try {","sourceCodeStart":332,"sourceCodeEnd":368,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/DoFnTester.java#L332-L368","documentation":"DoFnTester only provides a RestrictionTracker for splittable DoFns. For a regular DoFn, its ProcessContext.restrictionTracker() is hardcoded to throw this UnsupportedOperationException since no restriction tracking exists.","triggerScenarios":"Invoking restrictionTracker() on the context of a DoFnTester that wraps a non-splittable DoFn.","commonSituations":"Tests written for splittable DoFns (with claim/restriction logic) being reused for plain DoFns; mistakenly asserting on the tracker in a regular DoFn unit test.","solutions":["Drop the restrictionTracker() call for regular DoFns","For splittable DoFns, test restriction tracking with a full pipeline run (TestPipeline) or a runner-level harness, not DoFnTester","Refactor shared test code so SDF-specific assertions only run when the fn implements splittable processing"],"exampleFix":"// before\nRestrictionTracker<?, ?> t = tester.processContext.restrictionTracker();\n// after\n// assert element outputs instead\nassertThat(tester.takeOutputElements(), contains(in));","handlingStrategy":"try-catch","validationCode":"// Guard: only splittable DoFns have restriction trackers\nif (isSplittable(myDoFn)) { tester.processContext.restrictionTracker(); }","typeGuard":"boolean hasRestrictionTracker(DoFn<?, ?> fn) {\n  return java.util.Arrays.stream(fn.getClass().getDeclaredMethods())\n      .anyMatch(m -> m.isAnnotationPresent(DoFn.GetInitialRestriction.class));\n}","tryCatchPattern":"try { RestrictionTracker<?, ?> t = ctx.restrictionTracker(); }\ncatch (UnsupportedOperationException e) { assert fnIsNotSplittable; }","preventionTips":["Write separate test harnesses for SDF vs. regular DoFns","Do not share assertion helpers that touch restriction state across fn types","Prefer TestPipeline for any fn using restriction tracking"],"tags":["java","apache-beam","dofn","testing","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-14T16:17:12.679Z"}