{"record":{"id":"e5356402d0346e4b","repo":"apache/beam","slug":"not-expected-to-access-restriction-from-a-regular-dofn-in","errorCode":null,"errorMessage":"Not expected to access Restriction from a regular DoFn in DoFnTester","messagePattern":"Not expected to access Restriction 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":344,"sourceCode":"            public TimeDomain timeDomain(DoFn<InputT, OutputT> doFn) {\n              throw new UnsupportedOperationException(\n                  \"Not expected to access TimeDomain from @ProcessElement\");\n            }\n\n            @Override\n            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","sourceCodeStart":326,"sourceCodeEnd":362,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/DoFnTester.java#L326-L362","documentation":"DoFnTester is a testing harness for regular (non-splittable) DoFns. Its internal ProcessContext exposes restriction() only for splittable-DoFn support; calling it on a regular DoFn's tester throws this UnsupportedOperationException because there is no restriction to return.","triggerScenarios":"Calling DoFnTester's processContext.restriction() (directly or via test code that assumes an SDF) while the wrapped fn is a plain DoFn that does not implement splittable processing.","commonSituations":"Reusing a generic test helper written for splittable DoFns against a regular DoFn; copy-pasting an SDF unit test for a non-SDF transform.","solutions":["Remove the restriction() call; a regular DoFn has no restriction to test","Use TestStream or a dedicated splittable-DoFn test harness instead of DoFnTester for SDF behavior","If the fn should be splittable, implement ProcessElement returning a ProcessContinuation and a GetInitialRestriction method, then test via a pipeline runner rather than DoFnTester"],"exampleFix":"// before\nObject r = tester.processContext.restriction();\n// after\n// regular DoFn: no restriction access; test outputs only\ntester.processElement(in);","handlingStrategy":"try-catch","validationCode":"// Only call restriction() if the fn is splittable\nif (myDoFn.getClass().getAnnotation(DoFn.BoundedPerElement.class) != null || usesRestriction(myDoFn)) { /* use SDF harness */ }","typeGuard":"boolean isSplittableDoFn(DoFn<?, ?> fn) {\n  return java.util.Arrays.stream(fn.getClass().getDeclaredMethods())\n      .anyMatch(m -> m.isAnnotationPresent(DoFn.GetInitialRestriction.class));\n}","tryCatchPattern":"try { Object r = tester.processContext.restriction(); }\ncatch (UnsupportedOperationException e) { // regular DoFn: skip restriction assertions\n}","preventionTips":["Only access restriction()/restrictionTracker() when the fn has a GetInitialRestriction method","Use DoFnTester only for plain DoFns; use TestPipeline for SDFs","Keep SDF and non-SDF test helpers separate"],"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"}