{"record":{"id":"a63d72756779c2f2","repo":"apache/beam","slug":"failed-to-set-field-to-proto-field-s","errorCode":null,"errorMessage":"Failed to set field to proto. field:%s","messagePattern":"Failed to set field to proto\\. field:(.+?)","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":538,"sourceCode":"    private final Descriptors.FieldDescriptor fieldDescriptor;\n    private final BeamToProtoConverter<BeamT, ProtoT> converter;\n\n    ToProtoFieldSetter(Descriptors.FieldDescriptor fieldDescriptor) {\n      this.fieldDescriptor = fieldDescriptor;\n      this.converter =\n          (BeamToProtoConverter<BeamT, ProtoT>) createBeamToProtoConverter(fieldDescriptor);\n    }\n\n    @Override\n    public void setToProto(\n        Message.Builder message, Schema.FieldType fieldType, @Nullable BeamT beamFieldValue) {\n      try {\n        if (beamFieldValue != null) {\n          ProtoT protoValue = converter.convert(beamFieldValue);\n          message.setField(fieldDescriptor, protoValue);\n        }\n      } catch (RuntimeException e) {\n        throw new RuntimeException(\n            String.format(\"Failed to set field to proto. field:%s\", fieldDescriptor.getName()), e);\n      }\n    }\n  }\n\n  static class ToProtoOneOfSetter implements ToProtoSetter<OneOfType.@Nullable Value> {\n    private final Descriptors.OneofDescriptor oneofDescriptor;\n    private final Map<String, ToProtoFieldSetter<Object, Object>> protoSetters;\n\n    ToProtoOneOfSetter(Descriptors.OneofDescriptor oneofDescriptor) {\n      this.oneofDescriptor = oneofDescriptor;\n      this.protoSetters = createConverters(oneofDescriptor.getFields());\n    }\n\n    private static Map<String, ToProtoFieldSetter<Object, Object>> createConverters(\n        List<Descriptors.FieldDescriptor> fieldDescriptors) {\n      Map<String, ToProtoFieldSetter<Object, Object>> converters = new LinkedHashMap<>();\n      for (Descriptors.FieldDescriptor fieldDescriptor : fieldDescriptors) {","sourceCodeStart":520,"sourceCodeEnd":556,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/extensions/protobuf/src/main/java/org/apache/beam/sdk/extensions/protobuf/ProtoBeamConverter.java#L520-L556","documentation":"ToProtoSetter.setToProto writes a Beam field value into a proto Message builder via reflection-like fieldDescriptor.setField. Any RuntimeException during convert or setField is rethrown as a RuntimeException naming the proto field, preserving the underlying cause.","triggerScenarios":"Building a proto Message from a Beam Row when the Beam field value cannot be converted to the proto field type or setField rejects the value (wrong class, repeated field misuse, descriptor mismatch).","commonSituations":"Beam schema field type drifts from the proto (e.g. Beam STRING vs proto int64); nullability mismatch; stale schema after proto regeneration; passing a Message built from a different descriptor set.","solutions":["Inspect e.getCause() for the actual conversion error","Align the Beam schema field types with the proto field types and rebuild the converter","Check null handling: the setter skips null beamFieldValue, so errors mean a non-null value failed conversion","Regenerate schemas after proto changes so descriptors match"],"exampleFix":"// before\n// Beam row field 'count' is STRING, proto field int64 -> setField throws\n// after\n// make Beam schema type match proto: use INT64 for 'count' (or STRING int64 in proto)","handlingStrategy":"validation","validationCode":"// check Beam schema type matches proto field type before converting\nif (!beamField.getType().getTypeName().toString().equals(ProtoCatalog.getBeamTypeFromFieldType(fieldDescriptor).getTypeName().toString())) throw new IllegalStateException(\"type mismatch on \" + fieldDescriptor.getName());","typeGuard":null,"tryCatchPattern":"try { setter.setToProto(builder, beamType, value); } catch (RuntimeException e) { throw new IllegalStateException(\"field \" + e.getMessage() + \" cause: \" + e.getCause(), e); }","preventionTips":["Keep Beam schema and proto descriptor generated together","Check e.getCause() for the real setField failure","Add round-trip (message->Row->message) tests per field type"],"tags":["protobuf","beam","field-conversion","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"}