{"record":{"id":"1eb282e55a4fa7c2","repo":"apache/beam","slug":"failed-to-get-oneof-from-proto-oneof-s-subfield-s","errorCode":null,"errorMessage":"Failed to get oneof from proto. oneof: %s, subfield: %s","messagePattern":"Failed to get oneof from proto\\. oneof: (.+?), subfield: (.+?)","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":451,"sourceCode":"        converters.put(field.getName(), createProtoToBeamConverter(field.getType()));\n      }\n      return converters;\n    }\n\n    @Override\n    public OneOfType.@Nullable Value getFromProto(Message message) {\n      Descriptors.Descriptor descriptor = message.getDescriptorForType();\n      for (Map.Entry<String, ProtoToBeamConverter<Object, Object>> entry : converter.entrySet()) {\n        String subFieldName = entry.getKey();\n        try {\n          ProtoToBeamConverter<Object, Object> value = entry.getValue();\n          Descriptors.FieldDescriptor fieldDescriptor = descriptor.findFieldByName(subFieldName);\n          if (message.hasField(fieldDescriptor)) {\n            Object protoValue = message.getField(fieldDescriptor);\n            return oneOfType.createValue(subFieldName, value.convert(protoValue));\n          }\n        } catch (RuntimeException e) {\n          throw new RuntimeException(\n              String.format(\n                  \"Failed to get oneof from proto. oneof: %s, subfield: %s\",\n                  field.getName(), subFieldName),\n              e);\n        }\n      }\n      return null;\n    }\n  }\n\n  static class ToProto implements SerializableFunction<Row, Message> {\n    private transient Descriptors.Descriptor descriptor;\n    private transient Map<String, ToProtoSetter<Object>> toProtos;\n\n    public ToProto(Descriptors.Descriptor descriptor) {\n      initialize(descriptor);\n    }\n","sourceCodeStart":433,"sourceCodeEnd":469,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/extensions/protobuf/src/main/java/org/apache/beam/sdk/extensions/protobuf/ProtoBeamConverter.java#L433-L469","documentation":"FromProtoOneOfGetter.getFromProto reads the currently-set member of a proto oneof and converts it to a Beam OneOfType value. If finding the subfield descriptor, hasField/getField, or the value conversion throws, it is wrapped in a RuntimeException naming the oneof field and subfield, keeping the root cause attached.","triggerScenarios":"Converting a proto message to a Beam Row where a oneof member's descriptor lookup fails (subfield name not found), or reading/converting the oneof member value throws a RuntimeException.","commonSituations":"Proto schema changed so a oneof subfield name no longer matches the Beam schema; descriptor mismatch between message instance and converter; a member converter throwing on unexpected values.","solutions":["Check the wrapped cause to identify the failing subfield","Ensure oneof subfield names in the proto match those used to build the Beam schema","Regenerate/rebuild schema artifacts after proto changes","Validate the message instance uses the same descriptor as the converter (same FileDescriptor set)"],"exampleFix":"// before\n// oneof { string a = 1; } renamed to b in proto, schema stale -> throws\n// after\n// update schema: oneof { string b = 1; } and regenerate the Beam schema/converter","handlingStrategy":"try-catch","validationCode":"// verify each oneof subfield resolves on the descriptor\nfor (String sub : oneOfFieldNames) { if (descriptor.findFieldByName(sub) == null) throw new IllegalStateException(\"missing oneof subfield \" + sub); }","typeGuard":null,"tryCatchPattern":"try { value = oneOfGetter.getFromProto(message); } catch (RuntimeException e) { LOG.error(\"oneof {} failed: {}\", e.getMessage(), e.getCause()); throw e; }","preventionTips":["Keep proto oneof member names stable across versions","Regenerate the Beam schema after any oneof change","Use one FileDescriptor set for schema build and runtime"],"tags":["protobuf","beam","oneof","exception-wrap"],"backgroundTag":"protobuf-unmarshal-failed","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"}