apache/flink · error · IllegalArgumentException
no codec for codecByte: {}
Error message
no codec for codecByte: {} What it means
AvroOutputFormat's embedded Codec enum maps a byte code to a compression codec; forCodecByte(byte) throws IllegalArgumentException when the byte does not match any known codec (null, deflate, snappy, bzip2, xz, zstd per the enum). It is used when parsing/validating codec settings, so an unknown byte means an unsupported or corrupt codec identifier.
Source
Thrown at flink-formats/flink-avro/src/main/java/org/apache/flink/formats/avro/AvroOutputFormat.java:77
this.codecByte = codecByte;
this.codecFactory = codecFactory;
}
private byte getCodecByte() {
return codecByte;
}
private CodecFactory getCodecFactory() {
return codecFactory;
}
private static Codec forCodecByte(byte codecByte) {
for (final Codec codec : Codec.values()) {
if (codec.getCodecByte() == codecByte) {
return codec;
}
}
throw new IllegalArgumentException("no codec for codecByte: " + codecByte);
}
}
private static final long serialVersionUID = 1L;
private final Class<E> avroValueType;
private transient Schema userDefinedSchema = null;
private transient Codec codec = null;
private transient DataFileWriter<E> dataFileWriter;
public AvroOutputFormat(Path filePath, Class<E> type) {
super(filePath);
this.avroValueType = type;
}
View on GitHub (pinned to 2f3c205e92)
Solutions
- Use the public codec setters with well-known names (e.g. setCodecAsString("snappy")) instead of raw bytes.
- Keep Flink/Avro versions aligned across client and cluster so both sides know the same codec set.
- Validate the byte against the known codec values before calling forCodecByte, and fail with a descriptive message.
- If a newer Avro wrote an unknown codec byte, upgrade flink-avro on the reading side to a version that supports it.
Example fix
// before
Codec c = Codec.forCodecByte(rawByte); // throws on unknown
// after
Codec c = Arrays.stream(Codec.values())
.filter(k -> k.getCodecByte() == rawByte)
.findFirst()
.orElseThrow(() -> new IllegalArgumentException(
"unsupported codec byte " + rawByte + "; upgrade flink-avro")); Defensive patterns
Strategy: validation
Validate before calling
boolean known = Arrays.stream(Codec.values())
.anyMatch(c -> c.getCodecByte() == rawByte);
if (!known) {
throw new IllegalArgumentException("unsupported codec byte: " + rawByte);
} Prevention
- Set codecs by name via the output format's setters, never raw bytes.
- Keep flink-avro versions identical on client and cluster.
- Bounds-check codec bytes in any custom serialization glue.
When it happens
Trigger: Constructing or deserializing an AvroOutputFormat whose codec byte was set from an unvalidated string/name that maps to no enum constant — e.g. serializing an AvroOutputFormat instance across a cluster where the codec field carried an out-of-range byte, or calling Codec.forCodecByte directly with an arbitrary value.
Common situations: Custom code mutating the codec field via reflection or partial deserialization; format class serialized with a different Flink/Avro plugin version that added new codecs the reader's enum lacks; validation code probing codec bytes without bounds checks.
Related errors
- Encountered exception when reading from avro format file
- Interrupted while waiting for the previous batch to be consu
- Option %s.%s is required for serialization
- Schema provided for '%s' format does not match the table sch
- {e.getMessage()}
AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14).
Data as JSON: /api/errors/a897ce3bdfbeb221.
Report an issue: GitHub.