Fixed an issue: Netty-14 (IllegalArgumentException when creating a dynamic buffer with 0 estimatedLength)

* Allowed zero initial capacity
* Made the exception message more specific
This commit is contained in:
Trustin Lee 2008-08-18 11:17:42 +00:00
parent a7c73d2e52
commit 2d6cfe9af6

View File

@ -51,8 +51,8 @@ public class DynamicChannelBuffer extends AbstractChannelBuffer {
} }
public DynamicChannelBuffer(ByteOrder endianness, int estimatedLength) { public DynamicChannelBuffer(ByteOrder endianness, int estimatedLength) {
if (estimatedLength <= 0) { if (estimatedLength < 0) {
throw new IllegalArgumentException("estimatedLength"); throw new IllegalArgumentException("estimatedLength: " + estimatedLength);
} }
if (endianness == null) { if (endianness == null) {
throw new NullPointerException("endianness"); throw new NullPointerException("endianness");
@ -245,6 +245,9 @@ public class DynamicChannelBuffer extends AbstractChannelBuffer {
int newCapacity; int newCapacity;
if (capacity() == 0) { if (capacity() == 0) {
newCapacity = initialCapacity; newCapacity = initialCapacity;
if (newCapacity == 0) {
newCapacity = 1;
}
} else { } else {
newCapacity = capacity(); newCapacity = capacity();
} }