{"record":{"id":"eca44061d42d81ef","repo":"apache/beam","slug":"failed-to-set-oneof-to-proto-oneof-s-number-d","errorCode":null,"errorMessage":"Failed to set oneof to proto. oneof: %s, number: %d","messagePattern":"Failed to set oneof to proto\\. oneof: (.+?), number: (.+?)","errorType":"exception","errorClass":"java.lang.RuntimeException","httpStatus":null,"severity":"error","filePath":"sdks/java/extensions/protobuf/src/main/java/org/apache/beam/sdk/extensions/protobuf/ProtoBeamConverter.java","lineNumber":581,"sourceCode":"    @Override\n    public void setToProto(\n        Message.Builder message, Schema.FieldType fieldType, OneOfType.@Nullable Value oneOfValue) {\n      if (oneOfValue != null) {\n        OneOfType oneOfType = fieldType.getLogicalType(OneOfType.class);\n        int number = oneOfValue.getCaseType().getValue();\n        try {\n          String subFieldName =\n              Preconditions.checkNotNull(oneOfType.getCaseEnumType().getEnumName(number));\n\n          ToProtoFieldSetter<Object, Object> protoSetter =\n              Preconditions.checkNotNull(\n                  protoSetters.get(subFieldName), \"No setter for field '%s'\", subFieldName);\n          protoSetter.setToProto(\n              message,\n              oneOfType.getOneOfSchema().getField(subFieldName).getType(),\n              oneOfValue.getValue());\n        } catch (RuntimeException e) {\n          throw new RuntimeException(\n              String.format(\n                  \"Failed to set oneof to proto. oneof: %s, number: %d\",\n                  oneofDescriptor.getName(), number),\n              e);\n        }\n      }\n    }\n  }\n}\n","sourceCodeStart":563,"sourceCodeEnd":591,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/extensions/protobuf/src/main/java/org/apache/beam/sdk/extensions/protobuf/ProtoBeamConverter.java#L563-L591","documentation":"ToProtoOneOfSetter sets the active member of a proto oneof when converting a Beam OneOfType value to proto. Failures while locating/invoking the subfield setter or converting the oneof value are wrapped in a RuntimeException identifying the oneof descriptor name and field number.","triggerScenarios":"Converting a Beam Row containing a OneOfType value to proto when: no registered setter exists for the subfield, the subfield name doesn't exist in the oneof schema, or the value conversion/setField throws.","commonSituations":"Beam oneof schema and proto oneof out of sync after regeneration; setting a oneof case whose proto member was removed/renamed; custom value type incompatible with the member's converter.","solutions":["Verify the OneOfType value's case name matches an existing oneof member in the proto descriptor","Regenerate the Beam schema and converters after proto changes","Check e.getCause() for the underlying conversion failure","Ensure the value passed to oneOfType.createValue matches the member's expected Beam type"],"exampleFix":"// before\nOneOf.Value v = oneOf.setValue(\"oldCase\", val); // case removed in proto\n// after\nOneOf.Value v = oneOf.setValue(\"newCase\", val); // keep cases in sync with proto","handlingStrategy":"validation","validationCode":"// ensure the oneof case exists before setting\nDescriptors.OneofDescriptor od = descriptor.getOneofs().get(0); boolean ok = false; for (int i = 0; i < od.getFieldCount(); i++) { if (od.getField(i).getName().equals(caseName)) ok = true; } if (!ok) throw new IllegalStateException(\"unknown oneof case \" + caseName);","typeGuard":null,"tryCatchPattern":"try { oneOfSetter.setToProto(builder, type, oneOfValue); } catch (RuntimeException e) { LOG.error(\"oneof set failed: {} cause {}\", e.getMessage(), e.getCause()); throw e; }","preventionTips":["Keep oneof case names/types synchronized between Beam schema and proto","Round-trip test every oneof case","Regenerate schema artifacts on proto change"],"tags":["protobuf","beam","oneof","exception-wrap"],"backgroundTag":"type-mismatch","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"}