{"record":{"id":"5312deb678d4bf3b","repo":"apache/pulsar","slug":"expected-messageidv5-got-messageid-getclass-5312de","errorCode":null,"errorMessage":"Expected MessageIdV5, got: ${messageId.getClass()}","messagePattern":"Expected MessageIdV5, got: (.+?)","errorType":"exception","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"pulsar-client-v5/src/main/java/org/apache/pulsar/client/impl/v5/ScalableQueueConsumer.java","lineNumber":225,"sourceCode":"    @Override\n    public String consumerName() {\n        return consumerConf.getConsumerName();\n    }\n\n    @Override\n    public Message<T> receive() throws PulsarClientException {\n        return receiveQueue.take();\n    }\n\n    @Override\n    public Message<T> receive(Duration timeout) throws PulsarClientException {\n        return receiveQueue.poll(timeout);\n    }\n\n    @Override\n    public void acknowledge(MessageId messageId) {\n        if (!(messageId instanceof MessageIdV5 id)) {\n            throw new IllegalArgumentException(\"Expected MessageIdV5, got: \" + messageId.getClass());\n        }\n        var future = segmentConsumers.get(id.segmentId());\n        if (future != null) {\n            future.thenAccept(c -> c.acknowledgeAsync(id.v4MessageId()));\n        }\n    }\n\n    @Override\n    public void acknowledge(MessageId messageId, Transaction txn) {\n        if (!(messageId instanceof MessageIdV5 id)) {\n            throw new IllegalArgumentException(\"Expected MessageIdV5, got: \" + messageId.getClass());\n        }\n        var future = segmentConsumers.get(id.segmentId());\n        if (future != null) {\n            future.thenAccept(c -> c.acknowledgeAsync(id.v4MessageId(), TransactionV5.unwrap(txn)));\n        }\n    }\n","sourceCodeStart":207,"sourceCodeEnd":243,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-client-v5/src/main/java/org/apache/pulsar/client/impl/v5/ScalableQueueConsumer.java#L207-L243","documentation":"ScalableQueueConsumer.acknowledge(MessageId) only accepts MessageIdV5 instances because acks must be routed to the owning segment via id.segmentId(). Passing any other MessageId implementation (v4 TopicMessageIdImpl, MessageIdImpl, etc.) throws an IllegalArgumentException immediately, before any broker interaction.","triggerScenarios":"Calling acknowledge() with a MessageId obtained from a different (v4) consumer or client, a MessageId deserialized from bytes via the v4 MessageId.fromByteArray, or a hand-constructed MessageIdImpl instead of the MessageIdV5 returned by this consumer's receive().","commonSituations":"Mixing v4 and v5 clients in one application (e.g. after a partial migration); forwarding messages across consumers and acking with the original MessageId; caching MessageIds from an older client version.","solutions":["Only pass MessageId values returned by this v5 consumer's receive methods","Convert foreign ids with MessageIdV5 (wrap the v4 id in a MessageIdV5 with the correct segmentId)","Check message.getSource() / consumer origin before acking in fan-out code","Add an instanceof check in your pipeline before calling acknowledge"],"exampleFix":"// before\nconsumer.acknowledge(someV4MessageId);\n// after\nif (messageId instanceof MessageIdV5 id) {\n    consumer.acknowledge(id);\n} else {\n    consumer.acknowledge(MessageIdV5.from(messageId)); // convert\n}","handlingStrategy":"type-guard","validationCode":"if (!(messageId instanceof MessageIdV5)) {\n    throw new IllegalArgumentException(\"ack requires MessageIdV5\");\n}","typeGuard":"static boolean isV5MessageId(MessageId id) {\n    return id instanceof MessageIdV5;\n}","tryCatchPattern":"try {\n    consumer.acknowledge(messageId);\n} catch (IllegalArgumentException e) {\n    log.error(\"wrong MessageId type for v5 consumer\", e);\n}","preventionTips":["Only ack with ids from the same v5 consumer","Convert foreign ids via MessageIdV5 before acking","Type-check ids in shared helper methods","Avoid mixing v4 and v5 clients in one pipeline"],"tags":["pulsar","messageid","type-mismatch","acknowledgement"],"backgroundTag":"wrong-messageid-type","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"}