{"record":{"id":"976b70c18e6a0163","repo":"apache/pulsar","slug":"size-of-data-received-by-shortschema-is-not-2","errorCode":null,"errorMessage":"Size of data received by ShortSchema is not 2","messagePattern":"Size of data received by ShortSchema is not 2","errorType":"exception","errorClass":"SchemaSerializationException","httpStatus":null,"severity":"error","filePath":"pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/ShortSchema.java","lineNumber":49,"sourceCode":"    private static final ShortSchema INSTANCE;\n    private static final SchemaInfo SCHEMA_INFO;\n\n    static {\n        SCHEMA_INFO = SchemaInfoImpl.builder()\n            .name(\"INT16\")\n            .type(SchemaType.INT16)\n            .schema(new byte[0]).build();\n        INSTANCE = new ShortSchema();\n    }\n\n    public static ShortSchema of() {\n        return INSTANCE;\n    }\n\n    @Override\n    public void validate(byte[] message) {\n        if (message.length != 2) {\n            throw new SchemaSerializationException(\"Size of data received by ShortSchema is not 2\");\n        }\n    }\n\n    @Override\n    public void validate(ByteBuf message) {\n        if (message.readableBytes() != 2) {\n            throw new SchemaSerializationException(\"Size of data received by ShortSchema is not 2\");\n        }\n    }\n\n    @Override\n    public byte[] encode(Short message) {\n        if (null == message) {\n            return null;\n        } else {\n            return new byte[] {\n                (byte) (message >>> 8),\n                message.byteValue()","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/ShortSchema.java#L31-L67","documentation":"Schema decode guard in ShortSchema.validate: a 16-bit (INT16) message must occupy exactly 2 bytes, but the received payload has a different length, so decode() aborts before reading the short; indicates a producer writing with an incompatible schema for the topic.","triggerScenarios":"Calling ShortSchema.decode()/validate() on payloads that are not 2 bytes — e.g. data written with ByteSchema/IntSchema, corrupted or truncated entries.","commonSituations":"Producer/consumer schema mismatch on the topic; decoding raw bytes from an external tool; a changed topic schema after migration.","solutions":["Ensure the producer uses the INT16 schema so exactly 2 bytes are written","Check for payload corruption or a wrong schema on the producing side"],"exampleFix":"// before\nShort v = Schema.INT16.decode(bytes);\n// after\nif (bytes.length != 2) {\n    throw new IllegalArgumentException(\"expected 2 bytes, got \" + bytes.length);\n}\nShort v = Schema.INT16.decode(bytes);","handlingStrategy":"validation","validationCode":"if (bytes == null || bytes.length != 2) { throw new IllegalArgumentException(\"ShortSchema payload must be 2 bytes\"); }","typeGuard":"boolean isShortPayload(byte[] b) { return b != null && b.length == 2; }","tryCatchPattern":"try { Short v = Schema.INT16.decode(bytes); } catch (SchemaSerializationException e) { log.error(\"bad payload size\", e); /* dead-letter */ }","preventionTips":["Declare Schema.INT16 on both producer and consumer","Verify topic schema before wiring consumers","Guard payload length before decoding"],"tags":["schema","serialization","pulsar-client"],"backgroundTag":"schema-validation-failed","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"}