{"record":{"id":"e925b6a755e0c2f0","repo":"netty/netty","slug":"inconsistent-byte-order","errorCode":null,"errorMessage":"inconsistent byte order","messagePattern":"inconsistent byte order","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"buffer/src/main/java/io/netty/buffer/Unpooled.java","lineNumber":495,"sourceCode":"            return copiedBuffer(buffers[0]);\n        }\n\n        // Merge the specified buffers into one buffer.\n        ByteOrder order = null;\n        int length = 0;\n        for (ByteBuf b: buffers) {\n            int bLen = b.readableBytes();\n            if (bLen <= 0) {\n                continue;\n            }\n            if (Integer.MAX_VALUE - length < bLen) {\n                throw new IllegalArgumentException(\n                        \"The total length of the specified buffers is too big.\");\n            }\n            length += bLen;\n            if (order != null) {\n                if (!order.equals(b.order())) {\n                    throw new IllegalArgumentException(\"inconsistent byte order\");\n                }\n            } else {\n                order = b.order();\n            }\n        }\n\n        if (length == 0) {\n            return EMPTY_BUFFER;\n        }\n\n        byte[] mergedArray = PlatformDependent.allocateUninitializedArray(length);\n        for (int i = 0, j = 0; i < buffers.length; i ++) {\n            ByteBuf b = buffers[i];\n            int bLen = b.readableBytes();\n            b.getBytes(b.readerIndex(), mergedArray, j, bLen);\n            j += bLen;\n        }\n","sourceCodeStart":477,"sourceCodeEnd":513,"githubUrl":"https://github.com/netty/netty/blob/70040aacae241e9ba371e758f5b86e470bd77ad1/buffer/src/main/java/io/netty/buffer/Unpooled.java#L477-L513","documentation":"Thrown by Unpooled.copiedBuffer(ByteBuf... buffers) when buffers disagree on byte order (endianness). Netty records the first buffer's order() and compares each subsequent buffer against it; any mismatch (e.g. mixing BIG_ENDIAN and LITTLE_ENDIAN) aborts the merge because a single backing array cannot represent mixed endianness coherently.","triggerScenarios":"Mixing ByteBufs of different endianness in one copiedBuffer call, e.g. one wrapped with .order(LITTLE_ENDIAN) and others left default BIG_ENDIAN.","commonSituations":"Interfacing with protocols having different byte orders (some legacy binary protocols are little-endian); merging buffers produced by different codecs each setting order() explicitly.","solutions":["Normalize endianness before merging: call buf.order(ByteOrder.BIG_ENDIAN) (or a single chosen order) on every input.","Convert each buffer's bytes to a canonical order before copiedBuffer.","Operate on raw byte[] via copiedBuffer(byte[]...) which has no endianness concept."],"exampleFix":"// before\nByteBuf out = Unpooled.copiedBuffer(bigEndianBuf, littleEndianBuf);\n\n// after\nByteBuf out = Unpooled.copiedBuffer(\n    bigEndianBuf.retain(),\n    littleEndianBuf.order(ByteOrder.BIG_ENDIAN));","handlingStrategy":"validation","validationCode":"ByteOrder target = ByteOrder.BIG_ENDIAN;\nfor (ByteBuf b : buffers) {\n    if (!target.equals(b.order())) {\n        b = b.order(target); // or reject\n    }\n}\nByteBuf out = Unpooled.copiedBuffer(buffers);","typeGuard":"static boolean consistentOrder(ByteBuf... bufs) {\n    ByteOrder ref = null;\n    for (ByteBuf b : bufs) {\n        if (ref == null) ref = b.order();\n        else if (!ref.equals(b.order())) return false;\n    }\n    return true;\n}","tryCatchPattern":null,"preventionTips":["Normalize endianness at the point buffers enter your pipeline.","Avoid calling order() on Netty buffers (deprecated); pick one canonical order.","Validate consistency in a helper before copiedBuffer."],"tags":["netty","buffer","unpooled","byte-order","endianness","illegal-argument"],"backgroundTag":null,"analyzedSha":"70040aacae241e9ba371e758f5b86e470bd77ad1","analyzedAt":"2026-08-14T01:29:15.551Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}