{"record":{"id":"74109b2edac4267b","repo":"apache/pulsar","slug":"failed-to-deserialize-longbitmap","errorCode":null,"errorMessage":"Failed to deserialize LongBitmap","messagePattern":"Failed to deserialize LongBitmap","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"pulsar-common/src/main/java/org/apache/pulsar/common/util/collections/ConcurrentRoaringBitmap.java","lineNumber":441,"sourceCode":"            bitmap.clear();\n            RoaringBitmap rb = BitSetUtil.bitmapOf(data);\n            bitmap.or(rb.toMutableRoaringBitmap());\n            removesSinceTrim = 0;\n        } finally {\n            lock.unlockWrite(stamp);\n        }\n    }\n\n    static ConcurrentRoaringBitmap deserialize(ByteBuf buf) {\n        try {\n            ByteBuffer nioBuffer = buf.nioBuffer(buf.readerIndex(), buf.readableBytes());\n            int startPosition = nioBuffer.position();\n            MutableRoaringBitmap bitmap = new MutableRoaringBitmap();\n            bitmap.deserialize(new ByteBufferDataInput(nioBuffer));\n            buf.skipBytes(nioBuffer.position() - startPosition);\n            return new ConcurrentRoaringBitmap(bitmap);\n        } catch (IOException e) {\n            throw new RuntimeException(\"Failed to deserialize LongBitmap\", e);\n        }\n    }\n\n    /**\n     * Trims the underlying bitmap if enough removals have accumulated or it's empty.\n     * Caller must hold the write lock and have already updated {@link #removesSinceTrim}.\n     */\n    private void maybeTrim() {\n        if (removesSinceTrim >= TRIM_AFTER_REMOVES || bitmap.isEmpty()) {\n            bitmap.trim();\n            removesSinceTrim = 0;\n        }\n    }\n\n    private static void validateRange(long value) {\n        if (value < 0 || value > MAX_UINT32) {\n            throw new IllegalArgumentException(\n                    \"Value out of range [0, \" + MAX_UINT32 + \"]: \" + value);","sourceCodeStart":423,"sourceCodeEnd":459,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-common/src/main/java/org/apache/pulsar/common/util/collections/ConcurrentRoaringBitmap.java#L423-L459","documentation":"ConcurrentRoaringBitmap.deserialize wraps IOException from the underlying RoaringBitmap deserialization in a RuntimeException('Failed to deserialize LongBitmap'). It indicates the byte buffer did not contain a valid serialized roaring bitmap.","triggerScenarios":"Calling deserialize(ByteBuf/ByteBuffer) whose bytes are truncated, corrupted, produced by a different serialization format, or at the wrong offset.","commonSituations":"Version/format changes between writer and reader, corrupt persistence or wire transfer, misaligned buffer positions when reading a stream of serialized bitmaps.","solutions":["Verify the bytes were produced by ConcurrentRoaringBitmap.serialize and are complete/untruncated","Check buffer reader/writer indices and offsets; deserialize expects the bitmap at the current position","Catch the RuntimeException and treat the payload as corrupt (rebuild from source data or skip)"],"exampleFix":"// before\nConcurrentRoaringBitmap bm = ConcurrentRoaringBitmap.deserialize(buf);\n// after\ntry {\n    ConcurrentRoaringBitmap bm = ConcurrentRoaringBitmap.deserialize(buf);\n} catch (RuntimeException e) {\n    log.warn(\"Corrupt LongBitmap payload\", e);\n    bm = new ConcurrentRoaringBitmap();\n}","handlingStrategy":"try-catch","validationCode":"static boolean looksLikeBitmap(ByteBuf buf) {\n    return buf != null && buf.readableBytes() > 0; // full validity only verifiable by deserializing\n}","typeGuard":null,"tryCatchPattern":"try {\n    ConcurrentRoaringBitmap bm = ConcurrentRoaringBitmap.deserialize(buf);\n} catch (RuntimeException e) {\n    // corrupted or foreign-format payload; rebuild or skip\n    log.warn(\"Failed to deserialize LongBitmap\", e);\n}","preventionTips":["Keep serialization format and library versions in sync across writers/readers","Frame serialized bitmaps with length prefixes to detect truncation","Persist a checksum alongside serialized bitmaps"],"tags":["java","serialization","corrupt-data"],"backgroundTag":"deserialization-failed","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"}