apache/beam · error · java.lang.RuntimeException
Failed to set oneof to proto. oneof
Error message
Failed to set oneof to proto. oneof: %s, number: %d
What it means
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.
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
Example fix
// before
OneOf.Value v = oneOf.setValue("oldCase", val); // case removed in proto
// after
OneOf.Value v = oneOf.setValue("newCase", val); // keep cases in sync with proto Defensive patterns
Strategy: validation
Validate before calling
// ensure the oneof case exists before setting
Descriptors.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); Try / catch
try { oneOfSetter.setToProto(builder, type, oneOfValue); } catch (RuntimeException e) { LOG.error("oneof set failed: {} cause {}", e.getMessage(), e.getCause()); throw e; } Prevention
- Keep oneof case names/types synchronized between Beam schema and proto
- Round-trip test every oneof case
- Regenerate schema artifacts on proto change
When it happens
Trigger: 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.
Common situations: 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.
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 oneof from proto. oneof
- Failed to get field from proto. field
- Failed to set field to proto. field
- bad type: , want
- base64 decode for failed
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/eca44061d42d81ef.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/java/extensions/protobuf/src/main/java/org/apache/beam/sdk/extensions/protobuf/ProtoBeamConverter.java:581
@Override
public void setToProto(
Message.Builder message, Schema.FieldType fieldType, OneOfType.@Nullable Value oneOfValue) {
if (oneOfValue != null) {
OneOfType oneOfType = fieldType.getLogicalType(OneOfType.class);
int number = oneOfValue.getCaseType().getValue();
try {
String subFieldName =
Preconditions.checkNotNull(oneOfType.getCaseEnumType().getEnumName(number));
ToProtoFieldSetter<Object, Object> protoSetter =
Preconditions.checkNotNull(
protoSetters.get(subFieldName), "No setter for field '%s'", subFieldName);
protoSetter.setToProto(
message,
oneOfType.getOneOfSchema().getField(subFieldName).getType(),
oneOfValue.getValue());
} catch (RuntimeException e) {
throw new RuntimeException(
String.format(
"Failed to set oneof to proto. oneof: %s, number: %d",
oneofDescriptor.getName(), number),
e);
}
}
}
}
}
View on GitHub (pinned to 12126d8942)