apache/pulsar · error · SchemaSerializationException

Size of data received by FloatSchema is not 4

Error message

Size of data received by FloatSchema is not 4

What it means

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().

Source

Thrown at pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/FloatSchema.java:49

    private static final FloatSchema INSTANCE;
    private static final SchemaInfo SCHEMA_INFO;

    static {
        SCHEMA_INFO = SchemaInfoImpl.builder()
                .name("Float")
                .type(SchemaType.FLOAT)
                .schema(new byte[0]).build();
        INSTANCE = new FloatSchema();
    }

    public static FloatSchema of() {
        return INSTANCE;
    }

    @Override
    public void validate(byte[] message) {
        if (message.length != 4) {
            throw new SchemaSerializationException("Size of data received by FloatSchema is not 4");
        }
    }

    @Override
    public void validate(ByteBuf message) {
        if (message.readableBytes() != 4) {
            throw new SchemaSerializationException("Size of data received by FloatSchema is not 4");
        }
    }

    @Override
    public byte[] encode(Float message) {
        if (null == message) {
            return null;
        } else {
            long bits = Float.floatToRawIntBits(message);
            return new byte[] {
                (byte) (bits >>> 24),

View on GitHub (pinned to 820761864e)

Solutions

  1. Ensure the producer encodes with Schema.FLOAT (4-byte little/big-endian per platform convention) not DOUBLE or STRING
  2. Check the topic's schema info (admin schemas get) to confirm it is FLOAT and matches the consumer
  3. Validate payload length == 4 before decode if consuming raw bytes

Example fix

// before
float v = Schema.FLOAT.decode(message);
// after
if (message != null && message.length == 4) { float v = Schema.FLOAT.decode(message); } else { /* handle bad payload */ }
Defensive patterns

Strategy: validation

Validate before calling

if (payload == null || payload.length != 4) throw new IllegalArgumentException("FLOAT payload must be 4 bytes, got " + (payload == null ? "null" : payload.length));

Type guard

boolean isFloatPayload(byte[] b) { return b != null && b.length == 4; }

Try / catch

try { float v = Schema.FLOAT.decode(payload); } catch (SchemaSerializationException e) { if (e.getMessage().contains("not 4")) { deadLetter(msg); } else throw e; }

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of apache/pulsar@820761864e (2026-09-06). Data as JSON: /api/errors/efe2ebc4c5311b84. Report an issue: GitHub.