{"record":{"id":"9a43ec74ab25146a","repo":"MyCATApache/Mycat-Server","slug":"heap-buffer","errorCode":null,"errorMessage":"Heap buffer","messagePattern":"Heap buffer","errorType":"exception","errorClass":"java.lang.UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/buffer/MyCatMemoryAllocator.java","lineNumber":145,"sourceCode":"\n    @Override\n    public ByteBuf ioBuffer() {\n        return alloc.ioBuffer();\n    }\n\n    @Override\n    public ByteBuf ioBuffer(int initialCapacity) {\n        return alloc.ioBuffer(initialCapacity);\n    }\n\n    @Override\n    public ByteBuf ioBuffer(int initialCapacity, int maxCapacity) {\n        return alloc.ioBuffer(initialCapacity, maxCapacity);\n    }\n\n    @Override\n    public ByteBuf heapBuffer() {\n        throw new UnsupportedOperationException(\"Heap buffer\");\n    }\n\n    @Override\n    public ByteBuf heapBuffer(int initialCapacity) {\n        throw new UnsupportedOperationException(\"Heap buffer\");\n    }\n\n    @Override\n    public ByteBuf heapBuffer(int initialCapacity, int maxCapacity) {\n        throw new UnsupportedOperationException(\"Heap buffer\");\n    }\n\n    @Override\n    public ByteBuf directBuffer() {\n        return alloc.directBuffer();\n    }\n\n    @Override","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/buffer/MyCatMemoryAllocator.java#L127-L163","documentation":"MyCatMemoryAllocator is a Netty ByteBufAllocator wrapper dedicated to off-heap (direct) memory management. It deliberately refuses to allocate on-heap buffers: heapBuffer() unconditionally throws UnsupportedOperationException(\"Heap buffer\") instead of delegating to the wrapped allocator. The error means the caller asked for a Java-heap-backed buffer in an allocator that only supports direct buffers.","triggerScenarios":"Calling alloc.heapBuffer() (the no-arg overload at line 145) on a MyCatMemoryAllocator instance, typically wherever code is written against the generic ByteBufAllocator interface and defaults to heap allocation.","commonSituations":"Frameworks or utility code (e.g. codecs, serialization helpers) that call heapBuffer() by default when handed any ByteBufAllocator; swapping MyCatMemoryAllocator in as a drop-in replacement for UnpooledByteBufAllocator/DefaultByteBufAllocator without auditing heap-buffer usage.","solutions":["Replace the heapBuffer() call with ioBuffer(), directBuffer(), or compositeDirectBuffer() — the allocator's supported APIs.","If a heap buffer is genuinely required, use a different allocator (e.g. new DefaultByteBufAllocator(...).heapBuffer()) for that code path instead of MyCatMemoryAllocator.","Audit call sites with a ByteBufAllocator parameter and make buffer-type selection explicit rather than relying on heap defaults.","If heap support is intentionally disabled, catch UnsupportedOperationException and fall back to a direct buffer."],"exampleFix":"// before\nByteBuf buf = allocator.heapBuffer();\n// after\nByteBuf buf = allocator.directBuffer(); // or allocator.ioBuffer()","handlingStrategy":"fallback","validationCode":"if (allocator instanceof MyCatMemoryAllocator) {\n    buf = allocator.directBuffer();\n} else {\n    buf = allocator.heapBuffer();\n}","typeGuard":"boolean supportsHeapBuffers(ByteBufAllocator a) {\n    return !(a instanceof MyCatMemoryAllocator);\n}","tryCatchPattern":"ByteBuf buf;\ntry {\n    buf = allocator.heapBuffer();\n} catch (UnsupportedOperationException e) {\n    buf = allocator.directBuffer();\n}","preventionTips":["Never call heapBuffer() on a MyCatMemoryAllocator; treat it as direct-only.","Encode buffer-type choice in a wrapper/helper rather than calling allocator methods directly at each site.","Search codebases for heapBuffer( calls before installing a direct-only allocator globally."],"tags":["netty","bytebuf","unsupported-operation","memory-allocation"],"backgroundTag":"unsupported-operation","analyzedSha":"65f8d8beb752f935752f2a0eec0ab017facab9ef","analyzedAt":"2026-09-11T00:12:21.696Z","contentChangedAt":"2026-09-11T00:12:21.696Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}