apache/beam · error · InvalidObjectException
Unknown mode for AvroSource
Error message
Unknown mode %s for AvroSource %s
What it means
AvroSource's Java serialization readResolve validates that the persisted mode enum is one of the supported values (SINGLEFILE or FILEPATTERN). An unknown mode means deserialized state is inconsistent, so it throws InvalidObjectException.
Solutions
- Rebuild the pipeline with a single consistent Beam SDK version
- Re-create the AvroSource instead of deserializing stale state
- Clear caches of serialized pipeline artifacts produced by an older Beam version
Example fix
null
Defensive patterns
Strategy: try-catch
Try / catch
try { ObjectInputStream in = ...; AvroSource<?> s = (AvroSource<?>) in.readObject(); } catch (InvalidObjectException e) { /* rebuild source from spec */ } Prevention
- Keep Beam SDK versions consistent across pipeline build and run environments
- Avoid persisting serialized Beam source objects across upgrades
- Reconstruct sources from AvroIO specs instead of caching serialized instances
When it happens
Trigger: Deserializing an AvroSource whose serialized mode field holds a value not in the Mode enum — only possible across incompatible Beam versions or hand-corrupted serialized source state.
Common situations: Pipeline state (e.g. cached source objects or job graphs) serialized by one Beam version and deserialized by another after the Mode enum changed.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- bad function
- is not supported
- Could not decode avro record from given bytes
- Could not encode avro from given row
- Error writing row to Avro
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/2181a028afc04eba.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/java/extensions/avro/src/main/java/org/apache/beam/sdk/extensions/avro/io/AvroSource.java:566
schema = parser.parse(schemaString);
schemaLogicalReferenceCache.put(schemaString, schema);
return schema;
}
// Reading the object from Java serialization typically does not go through the constructor,
// we use readResolve to replace the constructed instance with one which uses the constructor
// allowing us to intern any schemas.
@SuppressWarnings("unused")
private Object readResolve() throws ObjectStreamException {
switch (getMode()) {
case SINGLE_FILE_OR_SUBRANGE:
return new AvroSource<>(
getSingleFileMetadata(), getMinBundleSize(), getStartOffset(), getEndOffset(), mode);
case FILEPATTERN:
return new AvroSource<>(
getFileOrPatternSpecProvider(), getEmptyMatchTreatment(), getMinBundleSize(), mode);
default:
throw new InvalidObjectException(
String.format("Unknown mode %s for AvroSource %s", getMode(), this));
}
}
/**
* A {@link Block} of Avro records.
*
* @param <T> The type of records stored in the block.
*/
static class AvroBlock<T> extends Block<T> {
// The current record in the block. Initialized in readNextRecord.
private @Nullable T currentRecord;
// The index of the current record in the block.
private long currentRecordIndex = 0;
private final Iterator<?> iterator;View on GitHub (pinned to 12126d8942)