{"record":{"id":"efe2ebc4c5311b84","repo":"apache/pulsar","slug":"size-of-data-received-by-floatschema-is-not-4","errorCode":null,"errorMessage":"Size of data received by FloatSchema is not 4","messagePattern":"Size of data received by FloatSchema is not 4","errorType":"exception","errorClass":"SchemaSerializationException","httpStatus":null,"severity":"error","filePath":"pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/FloatSchema.java","lineNumber":49,"sourceCode":"    private static final FloatSchema INSTANCE;\n    private static final SchemaInfo SCHEMA_INFO;\n\n    static {\n        SCHEMA_INFO = SchemaInfoImpl.builder()\n                .name(\"Float\")\n                .type(SchemaType.FLOAT)\n                .schema(new byte[0]).build();\n        INSTANCE = new FloatSchema();\n    }\n\n    public static FloatSchema of() {\n        return INSTANCE;\n    }\n\n    @Override\n    public void validate(byte[] message) {\n        if (message.length != 4) {\n            throw new SchemaSerializationException(\"Size of data received by FloatSchema is not 4\");\n        }\n    }\n\n    @Override\n    public void validate(ByteBuf message) {\n        if (message.readableBytes() != 4) {\n            throw new SchemaSerializationException(\"Size of data received by FloatSchema is not 4\");\n        }\n    }\n\n    @Override\n    public byte[] encode(Float message) {\n        if (null == message) {\n            return null;\n        } else {\n            long bits = Float.floatToRawIntBits(message);\n            return new byte[] {\n                (byte) (bits >>> 24),","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/FloatSchema.java#L31-L67","documentation":"FloatSchema.validate(byte[]) checks that the payload is exactly 4 bytes (a 32-bit float) before decoding. A payload of any other length cannot be interpreted as a FLOAT, so a SchemaSerializationException is thrown, typically via decode().","triggerScenarios":"Calling Schema.FLOAT.decode(byte[]) or a consumer with FLOAT schema receiving a message whose raw payload byte[] length != 4 (e.g. 0, 8, or arbitrary text).","commonSituations":"Producer and consumer disagree on schema (producer sent double/8 bytes or a serialized string); reading a raw topic without schema awareness; corrupted or truncated messages.","solutions":["Ensure the producer encodes with Schema.FLOAT (4-byte little/big-endian per platform convention) not DOUBLE or STRING","Check the topic's schema info (admin schemas get) to confirm it is FLOAT and matches the consumer","Validate payload length == 4 before decode if consuming raw bytes"],"exampleFix":"// before\nfloat v = Schema.FLOAT.decode(message);\n// after\nif (message != null && message.length == 4) { float v = Schema.FLOAT.decode(message); } else { /* handle bad payload */ }","handlingStrategy":"validation","validationCode":"if (payload == null || payload.length != 4) throw new IllegalArgumentException(\"FLOAT payload must be 4 bytes, got \" + (payload == null ? \"null\" : payload.length));","typeGuard":"boolean isFloatPayload(byte[] b) { return b != null && b.length == 4; }","tryCatchPattern":"try { float v = Schema.FLOAT.decode(payload); } catch (SchemaSerializationException e) { if (e.getMessage().contains(\"not 4\")) { deadLetter(msg); } else throw e; }","preventionTips":["Always encode with Schema.FLOAT on the producer","Verify topic schema matches FLOAT before subscribing","Validate payload size when consuming raw bytes"],"tags":["schema","serialization","float"],"backgroundTag":"schema-payload-size-mismatch","analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}