{"record":{"id":"a897ce3bdfbeb221","repo":"apache/flink","slug":"no-codec-for-codecbyte","errorCode":null,"errorMessage":"no codec for codecByte: {}","messagePattern":"no codec for codecByte: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"flink-formats/flink-avro/src/main/java/org/apache/flink/formats/avro/AvroOutputFormat.java","lineNumber":77,"sourceCode":"            this.codecByte = codecByte;\n            this.codecFactory = codecFactory;\n        }\n\n        private byte getCodecByte() {\n            return codecByte;\n        }\n\n        private CodecFactory getCodecFactory() {\n            return codecFactory;\n        }\n\n        private static Codec forCodecByte(byte codecByte) {\n            for (final Codec codec : Codec.values()) {\n                if (codec.getCodecByte() == codecByte) {\n                    return codec;\n                }\n            }\n            throw new IllegalArgumentException(\"no codec for codecByte: \" + codecByte);\n        }\n    }\n\n    private static final long serialVersionUID = 1L;\n\n    private final Class<E> avroValueType;\n\n    private transient Schema userDefinedSchema = null;\n\n    private transient Codec codec = null;\n\n    private transient DataFileWriter<E> dataFileWriter;\n\n    public AvroOutputFormat(Path filePath, Class<E> type) {\n        super(filePath);\n        this.avroValueType = type;\n    }\n","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-formats/flink-avro/src/main/java/org/apache/flink/formats/avro/AvroOutputFormat.java#L59-L95","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nCodec c = Codec.forCodecByte(rawByte); // throws on unknown\n\n// after\nCodec c = Arrays.stream(Codec.values())\n        .filter(k -> k.getCodecByte() == rawByte)\n        .findFirst()\n        .orElseThrow(() -> new IllegalArgumentException(\n                \"unsupported codec byte \" + rawByte + \"; upgrade flink-avro\"));","handlingStrategy":"validation","validationCode":"boolean known = Arrays.stream(Codec.values())\n        .anyMatch(c -> c.getCodecByte() == rawByte);\nif (!known) {\n    throw new IllegalArgumentException(\"unsupported codec byte: \" + rawByte);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["avro","format","codec","validation","versioning"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}