{"record":{"id":"7696f6d990a615d0","repo":"apache/pulsar","slug":"this-method-cannot-be-used-under-this-separated-en","errorCode":null,"errorMessage":"This method cannot be used under this SEPARATED encoding type","messagePattern":"This method cannot be used under this SEPARATED encoding type","errorType":"exception","errorClass":"SchemaSerializationException","httpStatus":null,"severity":"error","filePath":"pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/KeyValueSchemaImpl.java","lineNumber":184,"sourceCode":"                message.getValue(),\n                valueSchema);\n        } else {\n            if (message.getValue() == null) {\n                return null;\n            }\n            return valueSchema.encode(topic, message.getValue());\n        }\n    }\n\n    @Override\n    public KeyValue<K, V> decode(byte[] bytes) {\n        return decode(bytes, null);\n    }\n\n    @Override\n    public KeyValue<K, V> decode(byte[] bytes, byte[] schemaVersion) {\n        if (this.keyValueEncodingType == KeyValueEncodingType.SEPARATED) {\n            throw new SchemaSerializationException(\"This method cannot be used under this SEPARATED encoding type\");\n        }\n        return KeyValue.decode(bytes, (keyBytes, valueBytes) -> decode(keyBytes, valueBytes, schemaVersion));\n    }\n\n    @Override\n    public KeyValue<K, V> decode(ByteBuf byteBuf) {\n        return decode(ByteBufUtil.getBytes(byteBuf));\n    }\n\n    @Override\n    public KeyValue<K, V> decode(String topic, byte[] data, byte[] schemaId) {\n        if (this.keyValueEncodingType == KeyValueEncodingType.SEPARATED) {\n            throw new SchemaSerializationException(\"This method cannot be used under this SEPARATED encoding type\");\n        }\n        return KeyValue.decode(data, (keyBytes, valueBytes) ->\n                decode(topic, keyBytes, valueBytes, schemaId));\n    }\n","sourceCodeStart":166,"sourceCodeEnd":202,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/KeyValueSchemaImpl.java#L166-L202","documentation":"KeyValueSchemaImpl.decode(byte[], byte[]) decodes an INLINE-encoded KeyValue (key and value concatenated in one buffer). If the schema was configured with KeyValueEncodingType.SEPARATED, key and value are stored separately and this method cannot decode them, so it throws SchemaSerializationException.","triggerScenarios":"Creating Schema.KeyValue(..., KeyValueEncodingType.SEPARATED) and then calling kvSchema.decode(bytes) or kvSchema.decode(bytes, schemaVersion) on a single combined byte array.","commonSituations":"Consuming a SEPARATED KeyValue topic with a decode call that assumes inline encoding; switching encoding type in producer code without updating consumer decode calls.","solutions":["Use decode(ByteBuf) with the separate key/value ByteBufs, or the decode(String topic, byte[] keyBytes, byte[] valueBytes, ...) variant for SEPARATED encoding","Re-create the KeyValue schema with KeyValueEncodingType.INLINE if you want single-buffer decode","Use Message.getValue() on the consumer which handles the configured encoding automatically"],"exampleFix":"// before\nKeyValue<K,V> kv = kvSchema.decode(payload);\n// after\nif (message.getReaderSchema() instanceof KeyValueSchemaImpl && ((KeyValueSchemaImpl)message.getReaderSchema()).getKeyValueEncodingType() == KeyValueEncodingType.SEPARATED) { KeyValue<K,V> kv = (KeyValue<K,V>) message.getValue(); } else { KeyValue<K,V> kv = kvSchema.decode(payload); }","handlingStrategy":"type-guard","validationCode":"if (kvSchema instanceof KeyValueSchemaImpl && ((KeyValueSchemaImpl<?,?>) kvSchema).getKeyValueEncodingType() == KeyValueEncodingType.SEPARATED) { /* use separate-decode path */ }","typeGuard":"static <K,V> boolean isSeparated(Schema<KeyValue<K,V>> s) { return s instanceof KeyValueSchemaImpl && ((KeyValueSchemaImpl<?,?>) s).getKeyValueEncodingType() == KeyValueEncodingType.SEPARATED; }","tryCatchPattern":"try { KeyValue<K,V> kv = kvSchema.decode(bytes, schemaVersion); } catch (SchemaSerializationException e) { if (e.getMessage().contains(\"SEPARATED\")) { kv = (KeyValue<K,V>) message.getValue(); } else throw e; }","preventionTips":["Always decode via Message.getValue() instead of raw bytes","Keep the KeyValueEncodingType constant shared between producer and consumer configs","Document the encoding type next to each KeyValue schema instance"],"tags":["schema","keyvalue","encoding"],"backgroundTag":"keyvalue-encoding-mismatch","analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}