{"record":{"id":"31bce8a83bcd566c","repo":"apache/beam","slug":"schema-element-unsupported-in-context","errorCode":null,"errorMessage":"Schema element unsupported in ${context}","messagePattern":"Schema element 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":336,"sourceCode":"      throw new UnsupportedOperationException(\n          \"Cannot access key as parameter outside of @OnTimer method.\");\n    }\n\n    @Override\n    public @Nullable Object sideInput(String tagId) {\n      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(","sourceCodeStart":318,"sourceCodeEnd":354,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/reflect/DoFnInvoker.java#L318-L354","documentation":"This UnsupportedOperationException is thrown by DoFnInvoker.BaseArgumentProvider.schemaElement when a schema-element parameter is requested in a DoFn invocation context that cannot resolve it. Schema elements (fields of the current row when the DoFn operates on a schema'd type, bound via @SchemaElementIndex) are only supplied by contexts that process schema rows; the base provider always throws as a guard. getErrorContext() names the invocation context in the message.","triggerScenarios":"Binding an @SchemaElementIndex-annotated parameter or calling schemaElement(index) in a context whose ArgumentProvider does not override it, e.g. @StartBundle, @FinishBundle, @OnTimer methods, or when the input type has no schema so the runner-provided ArgumentProvider never overrides schemaElement(int).","commonSituations":"Declaring schema-element parameters on lifecycle methods like @StartBundle instead of @ProcessElement; using a DoFn over a POJO/Row without a registered schema so the invoker falls back to the base provider; custom test ArgumentProviders extending BaseArgumentProvider without overriding schemaElement.","solutions":["Move the @SchemaElementIndex parameter onto the @ProcessElement method so it is resolved by the process-element ArgumentProvider.","Ensure the input PCollection's type has a registered schema (SchemaRegistry / @DefaultSchema annotation) so the runner supplies schema elements.","Access the full element via the element parameter and read fields directly if schema binding is not required.","If implementing a custom ArgumentProvider, override schemaElement(int) to return the field value for the current row."],"exampleFix":"// before\n@StartBundle\npublic void startBundle(StartBundleContext c, @SchemaElementIndex(0) String id) { // throws\n}\n\n// after\n@ProcessElement\npublic void processElement(ProcessContext c, @SchemaElementIndex(0) String id) {\n  handle(c, id);\n}","handlingStrategy":"validation","validationCode":"// Ensure the input type has a registered schema and schema params are on @ProcessElement only.\nSchema s = pcollection.getSchema();\nif (s == null) throw new IllegalArgumentException(\"Input type has no schema; @SchemaElementIndex params unsupported\");","typeGuard":"if (context instanceof DoFn.ProcessContext && pcollection.getSchema() != null) {\n  // schema element binding is supported\n}","tryCatchPattern":"try {\n  bindSchemaElements();\n} catch (UnsupportedOperationException e) {\n  // fall back to reading fields from the full element object\n}","preventionTips":["Register a schema (@DefaultSchema) for the input type before using @SchemaElementIndex.","Declare schema-element parameters only on @ProcessElement.","Prefer plain element access when schema binding is not required."],"tags":["apache-beam","java","unsupported-operation","schema","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"}