{"record":{"id":"b30dcc48cb14751f","repo":"apache/cassandra","slug":"unable-to-allocate-s","errorCode":null,"errorMessage":"Unable to allocate %s","messagePattern":"Unable to allocate (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cache/SerializingCache.java","lineNumber":96,"sourceCode":"\n    private V deserialize(RefCountedMemory mem)\n    {\n        try\n        {\n            return serializer.deserialize(new MemoryInputStream(mem));\n        }\n        catch (IOException e)\n        {\n            logger.trace(\"Cannot fetch in memory data, we will fallback to read from disk \", e);\n            return null;\n        }\n    }\n\n    private RefCountedMemory serialize(V value)\n    {\n        long serializedSize = serializer.serializedSize(value);\n        if (serializedSize > Integer.MAX_VALUE)\n            throw new IllegalArgumentException(String.format(\"Unable to allocate %s\", FBUtilities.prettyPrintMemory(serializedSize)));\n\n        RefCountedMemory freeableMemory;\n        try\n        {\n            freeableMemory = new RefCountedMemory(serializedSize);\n        }\n        catch (OutOfMemoryError e)\n        {\n            return null;\n        }\n\n        try\n        {\n            serializer.serialize(value, new WrappedDataOutputStreamPlus(new MemoryOutputStream(freeableMemory)));\n        }\n        catch (IOException e)\n        {\n            freeableMemory.unreference();","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cache/SerializingCache.java#L78-L114","documentation":"serialize() measures a value's serialized size via the configured ISerializer and allocates a RefCountedMemory buffer of that exact size. If serializer.serializedSize(value) reports more than Integer.MAX_VALUE bytes, no int-length buffer can exist, so it throws IllegalArgumentException('Unable to allocate <size>'). This is the check on the serializer-provided path (error [92] is the lambda-sizer path).","triggerScenarios":"Putting a value into a SerializingCache when serializer.serializedSize(value) returns a value > Integer.MAX_VALUE; a serializer that mis-measures (returns huge/negative-wrapping sizes) also lands here.","commonSituations":"Caching rows with very large cells/collections exceeding 2GiB serialized; buggy custom ISerializer whose serializedSize disagrees with actual content; values that grew across version upgrades beyond the int limit.","solutions":["Reduce the size of values put into the cache so each serializes under 2GiB.","Fix or validate the ISerializer so serializedSize matches real content and never exceeds Integer.MAX_VALUE.","Check value size before put() and bypass the cache for oversized entries.","Store oversized data outside the cache (direct I/O / disk) and cache only references or metadata."],"exampleFix":"// before\nlong serializedSize = serializer.serializedSize(value);\nif (serializedSize > Integer.MAX_VALUE)\n    throw new IllegalArgumentException(String.format(\"Unable to allocate %s\", FBUtilities.prettyPrintMemory(serializedSize)));\n// after\nlong serializedSize = serializer.serializedSize(value);\nif (serializedSize > Integer.MAX_VALUE) {\n    logger.warn(\"Value too large for cache ({}); bypassing cache\", FBUtilities.prettyPrintMemory(serializedSize));\n    return null;\n}","handlingStrategy":"validation","validationCode":"// check serialized size before put\nlong serializedSize = serializer.serializedSize(value);\nif (serializedSize > Integer.MAX_VALUE || serializedSize < 0) {\n    throw new IllegalArgumentException(\"Serializer reports invalid size: \" + serializedSize);\n}","typeGuard":"boolean cacheable(V v, ISerializer<V> s) { long n = s.serializedSize(v); return n >= 0 && n <= Integer.MAX_VALUE; }","tryCatchPattern":"try {\n    cache.put(key, value);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().startsWith(\"Unable to allocate\")) {\n        bypassCache(value); // too large for cache\n    } else throw e;\n}","preventionTips":["Audit custom ISerializer.serializedSize implementations for correctness.","Bound the size of values offered to SerializingCache.","Bypass the cache for entries over 2GiB and store them elsewhere.","Watch for values growing past the int limit after upgrades."],"tags":["cache","serialization","memory-allocation"],"backgroundTag":"payload-too-large","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}