{"record":{"id":"af178806760afcf9","repo":"apache/pulsar","slug":"invalid-messageid-value","errorCode":null,"errorMessage":"Invalid messageId value","messagePattern":"Invalid messageId value","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"pulsar-websocket/src/main/java/org/apache/pulsar/websocket/ReaderHandler.java","lineNumber":405,"sourceCode":"\n    private MessageId getMessageId() {\n        MessageId messageId = MessageId.latest;\n        String messageIdParam = queryParams.get(\"messageId\");\n        if (isNotBlank(messageIdParam)) {\n            if (messageIdParam.equals(\"earliest\")) {\n                messageId = MessageId.earliest;\n            } else if (!messageIdParam.equals(\"latest\")) {\n                final byte[] decoded;\n                try {\n                    decoded = Base64.getDecoder().decode(messageIdParam);\n                } catch (IllegalArgumentException e) {\n                    throw new IllegalArgumentException(\"Invalid messageId base64 value\", e);\n                }\n\n                try {\n                    messageId = MessageIdImpl.fromByteArray(decoded);\n                } catch (IOException | RuntimeException e) {\n                    throw new IllegalArgumentException(\"Invalid messageId value\", e);\n                }\n            }\n        }\n        return messageId;\n    }\n\n}\n","sourceCodeStart":387,"sourceCodeEnd":413,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-websocket/src/main/java/org/apache/pulsar/websocket/ReaderHandler.java#L387-L413","documentation":"ReaderHandler.getMessageId successfully Base64-decodes the 'messageId' parameter, but MessageIdImpl.fromByteArray cannot parse the decoded bytes into a valid MessageId (wrong length, malformed ledger/entry layout), so it rethrows as 'Invalid messageId value'. The bytes were encoded correctly but are not a Pulsar MessageId serialized form.","triggerScenarios":"?messageId=<base64> decodes cleanly but the bytes are not a serialized MessageId — e.g. random data, a Pulsar broker messageId from a different serialization format, or a base64 of a string like 'ledger:entry'.","commonSituations":"Base64-encoding a textual message-id representation instead of the raw byte array from MessageId.toByteArray(); mixing message id formats across Pulsar versions; decoding an ack-set-augmented id whose byte layout was hand-trimmed incorrectly.","solutions":["Serialize the id with MessageId.toByteArray() on the producer side and base64-encode those exact bytes before passing them as ?messageId","Use the SDK's built-in base64 message-id helpers instead of hand-rolling the encoding","Confirm the id comes from the same Pulsar cluster/version (serialization format compatibility)","Fall back to 'earliest' or 'latest' when a concrete id is unavailable"],"exampleFix":"// before\nString param = Base64.getEncoder().encodeToString(msgId.toString().getBytes());\n// after\nString param = Base64.getEncoder().encodeToString(msgId.toByteArray());","handlingStrategy":"validation","validationCode":"byte[] raw = Base64.getDecoder().decode(messageIdParam); if (raw.length < 12) { throw new IllegalArgumentException(\"decoded messageId too short to be a Pulsar MessageId\"); }","typeGuard":"boolean isPlausibleMessageId(byte[] decoded) { return decoded != null && decoded.length >= new MessageIdImpl(0,0,0).toByteArray().length; }","tryCatchPattern":"try { byte[] decoded = Base64.getDecoder().decode(param); return MessageIdImpl.fromByteArray(decoded); } catch (IOException | RuntimeException e) { return MessageId.latest; }","preventionTips":["Only encode MessageId.toByteArray() output — never the id's toString()","Round-trip test: decode(base64(encode(id))).equals(id)","Use SDK helpers for message-id <-> base64 conversion","Keep producer and consumer on compatible Pulsar client versions"],"tags":["websocket","messageid","serialization","validation"],"backgroundTag":"invalid-message-id","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"}