From 2d6cfe9af6a8ed85c4ee43c435c791a0a261bb08 Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Mon, 18 Aug 2008 11:17:42 +0000 Subject: [PATCH] Fixed an issue: Netty-14 (IllegalArgumentException when creating a dynamic buffer with 0 estimatedLength) * Allowed zero initial capacity * Made the exception message more specific --- .../java/org/jboss/netty/buffer/DynamicChannelBuffer.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jboss/netty/buffer/DynamicChannelBuffer.java b/src/main/java/org/jboss/netty/buffer/DynamicChannelBuffer.java index 943a3413c7..ba95fa80bd 100644 --- a/src/main/java/org/jboss/netty/buffer/DynamicChannelBuffer.java +++ b/src/main/java/org/jboss/netty/buffer/DynamicChannelBuffer.java @@ -51,8 +51,8 @@ public class DynamicChannelBuffer extends AbstractChannelBuffer { } public DynamicChannelBuffer(ByteOrder endianness, int estimatedLength) { - if (estimatedLength <= 0) { - throw new IllegalArgumentException("estimatedLength"); + if (estimatedLength < 0) { + throw new IllegalArgumentException("estimatedLength: " + estimatedLength); } if (endianness == null) { throw new NullPointerException("endianness"); @@ -245,6 +245,9 @@ public class DynamicChannelBuffer extends AbstractChannelBuffer { int newCapacity; if (capacity() == 0) { newCapacity = initialCapacity; + if (newCapacity == 0) { + newCapacity = 1; + } } else { newCapacity = capacity(); }