{"record":{"id":"7613aa7d2fc45781","repo":"apache/flink","slug":"failed-to-deserialize-bitmap-from-bytes","errorCode":null,"errorMessage":"Failed to deserialize bitmap from bytes.","messagePattern":"Failed to deserialize bitmap from bytes\\.","errorType":"exception","errorClass":"DeserializationException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/types/bitmap/RoaringBitmapData.java","lineNumber":69,"sourceCode":"    }\n\n    // ~ Static Methods ----------------------------------------------------------------\n\n    public static RoaringBitmapData empty() {\n        return new RoaringBitmapData();\n    }\n\n    public static RoaringBitmapData from(@Nonnull Bitmap other) {\n        return new RoaringBitmapData(toRoaringBitmapData(other));\n    }\n\n    public static RoaringBitmapData fromBytes(@Nonnull byte[] bytes)\n            throws DeserializationException {\n        RoaringBitmapData rb32 = new RoaringBitmapData();\n        try {\n            rb32.roaringBitmap.deserialize(ByteBuffer.wrap(bytes));\n        } catch (Exception e) {\n            throw new DeserializationException(\"Failed to deserialize bitmap from bytes.\", e);\n        }\n        return rb32;\n    }\n\n    public static RoaringBitmapData fromArray(@Nonnull int[] values) {\n        RoaringBitmapData rb32 = new RoaringBitmapData();\n        rb32.roaringBitmap.add(values);\n        return rb32;\n    }\n\n    public static RoaringBitmapData toRoaringBitmapData(Bitmap bm) throws IllegalArgumentException {\n        if (!(bm instanceof RoaringBitmapData)) {\n            throw new IllegalArgumentException(\"Unsupported bitmap type: \" + bm.getClass() + \".\");\n        }\n        return (RoaringBitmapData) bm;\n    }\n\n    // ~ Bitmap Interface Implementations ------------------------------------------------","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/types/bitmap/RoaringBitmapData.java#L51-L87","documentation":"Thrown by RoaringBitmapData.fromBytes(byte[]) when the underlying RoaringBitmap library fails to deserialize the given byte array. The bytes are wrapped in a ByteBuffer and handed to RoaringBitmap.deserialize; any exception (bad cookie/version, truncated array, non-roaring data) is rethrown as a DeserializationException with this message and the original cause attached.","triggerScenarios":"Calling RoaringBitmapData.fromBytes(bytes) with bytes that are not a complete serialized RoaringBitmap: truncated arrays, arrays produced by a different bitmap library or format, corrupted state, or bytes serialized with an incompatible RoaringBitmap version whose serialized cookie/layout differs.","commonSituations":"Reading bitmap state back from a store (DB BLOB, Kafka message, checkpoint/saved state) where the writer used a different serializer or RoaringBitmap version; network truncation; accidentally passing raw user bitset bytes instead of roaring-serialized bytes.","solutions":["Inspect the attached cause (e) in the DeserializationException — RoaringBitmap's exception tells you whether it is a cookie mismatch, truncation, or garbage input.","Verify the byte array was produced by RoaringBitmap.serialize()/RoaringBitmapData serialization on the same RoaringBitmap version on both ends; align versions in pom.xml if they differ.","Check for truncation: log bytes.length and compare with the size recorded when the bitmap was written (roaring serialized size is available before writing).","If the data may come from other bitmap types, deserialize via the type tag your writer stored instead of assuming RoaringBitmapData."],"exampleFix":"// before\nRoaringBitmapData bitmap = RoaringBitmapData.fromBytes(bytes);\n\n// after\nRoaringBitmapData bitmap;\ntry {\n    bitmap = RoaringBitmapData.fromBytes(bytes);\n} catch (DeserializationException e) {\n    throw new IllegalStateException(\"Corrupt bitmap payload (\" + bytes.length + \" bytes)\", e.getCause());\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    RoaringBitmapData rb = RoaringBitmapData.fromBytes(bytes);\n} catch (DeserializationException e) {\n    // inspect e.getCause(): cookie mismatch => version skew; IBRunOverrun/truncated => corrupt payload\n    log.error(\"Bitmap payload unreadable ({} bytes)\", bytes.length, e.getCause());\n    throw e;\n}","preventionTips":["Pin the same RoaringBitmap dependency version on writer and reader sides.","Store the byte length alongside the payload and verify before deserializing.","Round-trip test serialization of every bitmap type you persist."],"tags":["bitmap","roaringbitmap","deserialization","data-corruption","flink-core"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}