diff --git a/transport/src/main/java/io/netty/channel/MessageList.java b/transport/src/main/java/io/netty/channel/MessageList.java index 79787efdcc..11a83ef25c 100644 --- a/transport/src/main/java/io/netty/channel/MessageList.java +++ b/transport/src/main/java/io/netty/channel/MessageList.java @@ -315,7 +315,26 @@ public final class MessageList implements Iterable { * {@link MessageList} and return itself. */ public MessageList add(MessageList src, int srcIdx, int srcLen) { - return add(src.elements, srcIdx, srcLen); + if (src == null) { + throw new NullPointerException("src"); + } + + if (srcIdx > src.size - srcLen) { + throw new IndexOutOfBoundsException(String.format( + "srcIdx(%d) + srcLen(%d) > src.size(%d)", srcIdx, srcLen, src.size)); + } + + modifications ++; + + final int dstIdx = size; + final int newSize = dstIdx + srcLen; + ensureCapacity(newSize); + + byteBufsOnly &= src.byteBufsOnly; + System.arraycopy(src.elements, srcIdx, elements, dstIdx, srcLen); + + size = newSize; + return this; } /**