apache/beam · error · java.lang.RuntimeException
Failed to set field to proto. field
Error message
Failed to set field to proto. field:%s
What it means
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.
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
Example fix
// before // Beam row field 'count' is STRING, proto field int64 -> setField throws // after // make Beam schema type match proto: use INT64 for 'count' (or STRING int64 in proto)
Defensive patterns
Strategy: validation
Validate before calling
// check Beam schema type matches proto field type before converting
if (!beamField.getType().getTypeName().toString().equals(ProtoCatalog.getBeamTypeFromFieldType(fieldDescriptor).getTypeName().toString())) throw new IllegalStateException("type mismatch on " + fieldDescriptor.getName()); Try / catch
try { setter.setToProto(builder, beamType, value); } catch (RuntimeException e) { throw new IllegalStateException("field " + e.getMessage() + " cause: " + e.getCause(), e); } Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- Failed to get field from proto. field
- Failed to get oneof from proto. oneof
- Failed to set oneof to proto. oneof
- bad type: , want
- base64 decode for failed
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/a63d72756779c2f2.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/java/extensions/protobuf/src/main/java/org/apache/beam/sdk/extensions/protobuf/ProtoBeamConverter.java:538
private final Descriptors.FieldDescriptor fieldDescriptor;
private final BeamToProtoConverter<BeamT, ProtoT> converter;
ToProtoFieldSetter(Descriptors.FieldDescriptor fieldDescriptor) {
this.fieldDescriptor = fieldDescriptor;
this.converter =
(BeamToProtoConverter<BeamT, ProtoT>) createBeamToProtoConverter(fieldDescriptor);
}
@Override
public void setToProto(
Message.Builder message, Schema.FieldType fieldType, @Nullable BeamT beamFieldValue) {
try {
if (beamFieldValue != null) {
ProtoT protoValue = converter.convert(beamFieldValue);
message.setField(fieldDescriptor, protoValue);
}
} catch (RuntimeException e) {
throw new RuntimeException(
String.format("Failed to set field to proto. field:%s", fieldDescriptor.getName()), e);
}
}
}
static class ToProtoOneOfSetter implements ToProtoSetter<OneOfType.@Nullable Value> {
private final Descriptors.OneofDescriptor oneofDescriptor;
private final Map<String, ToProtoFieldSetter<Object, Object>> protoSetters;
ToProtoOneOfSetter(Descriptors.OneofDescriptor oneofDescriptor) {
this.oneofDescriptor = oneofDescriptor;
this.protoSetters = createConverters(oneofDescriptor.getFields());
}
private static Map<String, ToProtoFieldSetter<Object, Object>> createConverters(
List<Descriptors.FieldDescriptor> fieldDescriptors) {
Map<String, ToProtoFieldSetter<Object, Object>> converters = new LinkedHashMap<>();
for (Descriptors.FieldDescriptor fieldDescriptor : fieldDescriptors) {View on GitHub (pinned to 12126d8942)