{"id":"22aad3b765e3ae58","repo":"apache/kafka","slug":"error-reading-field-name-detail","errorCode":null,"errorMessage":"Error reading field '${name}': ${detail}","messagePattern":"Error reading field '(.+?)': (.+?)","errorType":"exception","errorClass":"SchemaException","httpStatus":null,"severity":"error","filePath":"clients/src/main/java/org/apache/kafka/common/protocol/types/Schema.java","lineNumber":120,"sourceCode":"            return cachedStruct;\n        }\n        Object[] objects = new Object[fields.length];\n        for (int i = 0; i < fields.length; i++) {\n            try {\n                if (tolerateMissingFieldsWithDefaults) {\n                    if (buffer.hasRemaining()) {\n                        objects[i] = fields[i].def.type.read(buffer);\n                    } else if (fields[i].def.hasDefaultValue) {\n                        objects[i] = fields[i].def.defaultValue;\n                    } else {\n                        throw new SchemaException(\"Missing value for field '\" + fields[i].def.name +\n                                \"' which has no default value.\");\n                    }\n                } else {\n                    objects[i] = fields[i].def.type.read(buffer);\n                }\n            } catch (Exception e) {\n                throw new SchemaException(\"Error reading field '\" + fields[i].def.name + \"': \" +\n                                          (e.getMessage() == null ? e.getClass().getName() : e.getMessage()));\n            }\n        }\n        return new Struct(this, objects);\n    }\n\n    /**\n     * The size of the given record\n     */\n    @Override\n    public int sizeOf(Object o) {\n        int size = 0;\n        Struct r = (Struct) o;\n        for (BoundField field : fields) {\n            try {\n                size += field.def.type.sizeOf(r.get(field));\n            } catch (Exception e) {\n                throw new SchemaException(\"Error computing size for field '\" + field.def.name + \"': \" +","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/apache/kafka/blob/c31c9215e131f8c17e79f8901b48c13ee6aa8e7a/clients/src/main/java/org/apache/kafka/common/protocol/types/Schema.java#L102-L138","documentation":"Thrown by Schema.read when the element Type.read for a struct field raises any exception. The wrapper attaches the offending field's name and the underlying cause's message (or class name), turning a generic buffer failure into a field-localized error. It usually masks a more specific exception from the field's Type (e.g. ArrayOf, STRING, INT*).","triggerScenarios":"Schema.read calls fields[i].def.type.read(buffer) inside a try/catch; any exception - SchemaException from ArrayOf/CompactArrayOf/TaggedFields, BufferUnderflowException, or a NumberFormatException from a primitive reader - is rethrown with this message naming fields[i].def.name.","commonSituations":"Decoding with the wrong API version's schema so a later field reads bytes that belong to the next field; truncated payload causing BufferUnderflowException partway through a struct; a nested array/string field hit one of its own length guards; corrupted log replay.","solutions":["Read the named field, then check the underlying message (e.g. 'Error reading array of size ...') which pinpoints the real failure in the element type.","Confirm the schema's field order/types match the API key + API version on the wire.","Verify the ByteBuffer is not exhausted and was not over-sliced before this struct.","For log/record data, validate integrity (kafka-dump-log) and confirm the producer version matches."],"exampleFix":"// before - generic catch hides the real cause\ncatch (SchemaException e) { log.error(\"read failed\", e); }\n\n// after - surface the underlying field type error\ntry {\n    return (Struct) schema.read(buf);\n} catch (SchemaException e) {\n    throw new IOException(\"failed reading field set beginning at offset \" + start + \": \" + e.getMessage(), e);\n}","handlingStrategy":"try-catch","validationCode":"// The 'detail' comes from the inner Type.read; you cannot pre-validate it\n// generically. Ensure the buffer has at least one byte per remaining field\n// as a cheap sanity check before read.\nint remainingFields = schema.fields().length - fieldsAlreadyRead;\nif (buffer.remaining() < remainingFields) {\n    // likely truncated payload; read() will wrap the cause into this error\n    log.debug(\"buffer may be short for {} fields\", remainingFields);\n}","typeGuard":null,"tryCatchPattern":"try {\n    Struct s = (Struct) schema.read(buffer);\n} catch (org.apache.kafka.common.protocol.types.SchemaException e) {\n    if (e.getMessage().startsWith(\"Error reading field '\")) {\n        // The suffix is the inner cause (e.g. a nested ArrayOf/TaggedFields\n        // failure). Surface the field name and the inner detail separately.\n        String field = extractQuoted(e.getMessage(), \"Error reading field '\");\n        log.error(\"Failed to deserialize field '{}': {}\", field, innerDetail(e));\n        throw new MalformedRecordException(field, e);\n    }\n    throw e;\n}","preventionTips":["Log the inner detail (the text after the colon) separately; it pinpoints which sub-type failed.","Treat any 'Error reading field' as a non-retryable frame error; the buffer position is corrupt.","When adding fields, verify the reader schema's nested types match the writer's encoding exactly.","Cross-check API versions on both sides so the field set and their encodings agree."],"tags":["protocol","serialization","schema","buffer-underflow","kafka-clients"],"analyzedSha":"c31c9215e131f8c17e79f8901b48c13ee6aa8e7a","analyzedAt":"2026-08-03T12:34:05.770Z","schemaVersion":2}