use checkPositive/checkPositiveOrZero (#8803)

Motivation:

We have a utility method to check for > 0 and >0 arguments. We should use it.

Modification:

use checkPositive/checkPositiveOrZero instead of if statement.

Result:

Re-use utility method.
This commit is contained in:
田欧 2019-01-31 16:06:59 +08:00 committed by Norman Maurer
parent fe4a59011a
commit a33200ca38
32 changed files with 114 additions and 199 deletions

View File

@ -38,6 +38,7 @@ import java.nio.channels.ScatteringByteChannel;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import static io.netty.util.internal.MathUtil.isOutOfBounds; import static io.netty.util.internal.MathUtil.isOutOfBounds;
import static io.netty.util.internal.ObjectUtil.checkPositiveOrZero;
/** /**
* A skeletal implementation of a buffer. * A skeletal implementation of a buffer.
@ -73,9 +74,7 @@ public abstract class AbstractByteBuf extends ByteBuf {
private int maxCapacity; private int maxCapacity;
protected AbstractByteBuf(int maxCapacity) { protected AbstractByteBuf(int maxCapacity) {
if (maxCapacity < 0) { checkPositiveOrZero(maxCapacity, "maxCapacity");
throw new IllegalArgumentException("maxCapacity: " + maxCapacity + " (expected: >= 0)");
}
this.maxCapacity = maxCapacity; this.maxCapacity = maxCapacity;
} }
@ -271,10 +270,7 @@ public abstract class AbstractByteBuf extends ByteBuf {
@Override @Override
public ByteBuf ensureWritable(int minWritableBytes) { public ByteBuf ensureWritable(int minWritableBytes) {
if (minWritableBytes < 0) { checkPositiveOrZero(minWritableBytes, "minWritableBytes");
throw new IllegalArgumentException(String.format(
"minWritableBytes: %d (expected: >= 0)", minWritableBytes));
}
ensureWritable0(minWritableBytes); ensureWritable0(minWritableBytes);
return this; return this;
} }
@ -302,10 +298,7 @@ public abstract class AbstractByteBuf extends ByteBuf {
@Override @Override
public int ensureWritable(int minWritableBytes, boolean force) { public int ensureWritable(int minWritableBytes, boolean force) {
ensureAccessible(); ensureAccessible();
if (minWritableBytes < 0) { checkPositiveOrZero(minWritableBytes, "minWritableBytes");
throw new IllegalArgumentException(String.format(
"minWritableBytes: %d (expected: >= 0)", minWritableBytes));
}
if (minWritableBytes <= writableBytes()) { if (minWritableBytes <= writableBytes()) {
return 0; return 0;
@ -1414,9 +1407,7 @@ public abstract class AbstractByteBuf extends ByteBuf {
* than the specified value. * than the specified value.
*/ */
protected final void checkReadableBytes(int minimumReadableBytes) { protected final void checkReadableBytes(int minimumReadableBytes) {
if (minimumReadableBytes < 0) { checkPositiveOrZero(minimumReadableBytes, "minimumReadableBytes");
throw new IllegalArgumentException("minimumReadableBytes: " + minimumReadableBytes + " (expected: >= 0)");
}
checkReadableBytes0(minimumReadableBytes); checkReadableBytes0(minimumReadableBytes);
} }

View File

@ -16,6 +16,8 @@
package io.netty.buffer; package io.netty.buffer;
import static io.netty.util.internal.ObjectUtil.checkPositiveOrZero;
import io.netty.util.ResourceLeakDetector; import io.netty.util.ResourceLeakDetector;
import io.netty.util.ResourceLeakTracker; import io.netty.util.ResourceLeakTracker;
import io.netty.util.internal.PlatformDependent; import io.netty.util.internal.PlatformDependent;
@ -222,9 +224,7 @@ public abstract class AbstractByteBufAllocator implements ByteBufAllocator {
} }
private static void validate(int initialCapacity, int maxCapacity) { private static void validate(int initialCapacity, int maxCapacity) {
if (initialCapacity < 0) { checkPositiveOrZero(initialCapacity, "initialCapacity");
throw new IllegalArgumentException("initialCapacity: " + initialCapacity + " (expected: 0+)");
}
if (initialCapacity > maxCapacity) { if (initialCapacity > maxCapacity) {
throw new IllegalArgumentException(String.format( throw new IllegalArgumentException(String.format(
"initialCapacity: %d (expected: not greater than maxCapacity(%d)", "initialCapacity: %d (expected: not greater than maxCapacity(%d)",
@ -249,9 +249,7 @@ public abstract class AbstractByteBufAllocator implements ByteBufAllocator {
@Override @Override
public int calculateNewCapacity(int minNewCapacity, int maxCapacity) { public int calculateNewCapacity(int minNewCapacity, int maxCapacity) {
if (minNewCapacity < 0) { checkPositiveOrZero(minNewCapacity, "minNewCapacity");
throw new IllegalArgumentException("minNewCapacity: " + minNewCapacity + " (expected: 0+)");
}
if (minNewCapacity > maxCapacity) { if (minNewCapacity > maxCapacity) {
throw new IllegalArgumentException(String.format( throw new IllegalArgumentException(String.format(
"minNewCapacity: %d (expected: not greater than maxCapacity(%d)", "minNewCapacity: %d (expected: not greater than maxCapacity(%d)",

View File

@ -43,6 +43,7 @@ import java.util.Locale;
import static io.netty.util.internal.MathUtil.isOutOfBounds; import static io.netty.util.internal.MathUtil.isOutOfBounds;
import static io.netty.util.internal.ObjectUtil.checkNotNull; import static io.netty.util.internal.ObjectUtil.checkNotNull;
import static io.netty.util.internal.ObjectUtil.checkPositiveOrZero;
import static io.netty.util.internal.StringUtil.NEWLINE; import static io.netty.util.internal.StringUtil.NEWLINE;
import static io.netty.util.internal.StringUtil.isSurrogate; import static io.netty.util.internal.StringUtil.isSurrogate;
@ -1000,9 +1001,7 @@ public final class ByteBufUtil {
} }
private static String hexDump(ByteBuf buffer, int fromIndex, int length) { private static String hexDump(ByteBuf buffer, int fromIndex, int length) {
if (length < 0) { checkPositiveOrZero(length, "length");
throw new IllegalArgumentException("length: " + length);
}
if (length == 0) { if (length == 0) {
return ""; return "";
} }
@ -1022,9 +1021,7 @@ public final class ByteBufUtil {
} }
private static String hexDump(byte[] array, int fromIndex, int length) { private static String hexDump(byte[] array, int fromIndex, int length) {
if (length < 0) { checkPositiveOrZero(length, "length");
throw new IllegalArgumentException("length: " + length);
}
if (length == 0) { if (length == 0) {
return ""; return "";
} }

View File

@ -16,6 +16,8 @@
package io.netty.buffer; package io.netty.buffer;
import static io.netty.util.internal.ObjectUtil.checkPositiveOrZero;
import io.netty.util.ByteProcessor; import io.netty.util.ByteProcessor;
import io.netty.util.internal.EmptyArrays; import io.netty.util.internal.EmptyArrays;
import io.netty.util.internal.PlatformDependent; import io.netty.util.internal.PlatformDependent;
@ -223,9 +225,7 @@ public final class EmptyByteBuf extends ByteBuf {
@Override @Override
public ByteBuf ensureWritable(int minWritableBytes) { public ByteBuf ensureWritable(int minWritableBytes) {
if (minWritableBytes < 0) { checkPositiveOrZero(minWritableBytes, "minWritableBytes");
throw new IllegalArgumentException("minWritableBytes: " + minWritableBytes + " (expected: >= 0)");
}
if (minWritableBytes != 0) { if (minWritableBytes != 0) {
throw new IndexOutOfBoundsException(); throw new IndexOutOfBoundsException();
} }
@ -234,9 +234,7 @@ public final class EmptyByteBuf extends ByteBuf {
@Override @Override
public int ensureWritable(int minWritableBytes, boolean force) { public int ensureWritable(int minWritableBytes, boolean force) {
if (minWritableBytes < 0) { checkPositiveOrZero(minWritableBytes, "minWritableBytes");
throw new IllegalArgumentException("minWritableBytes: " + minWritableBytes + " (expected: >= 0)");
}
if (minWritableBytes == 0) { if (minWritableBytes == 0) {
return 0; return 0;
@ -1048,9 +1046,7 @@ public final class EmptyByteBuf extends ByteBuf {
} }
private ByteBuf checkIndex(int index, int length) { private ByteBuf checkIndex(int index, int length) {
if (length < 0) { checkPositiveOrZero(length, "length");
throw new IllegalArgumentException("length: " + length);
}
if (index != 0 || length != 0) { if (index != 0 || length != 0) {
throw new IndexOutOfBoundsException(); throw new IndexOutOfBoundsException();
} }
@ -1058,9 +1054,7 @@ public final class EmptyByteBuf extends ByteBuf {
} }
private ByteBuf checkLength(int length) { private ByteBuf checkLength(int length) {
if (length < 0) { checkPositiveOrZero(length, "length");
throw new IllegalArgumentException("length: " + length + " (expected: >= 0)");
}
if (length != 0) { if (length != 0) {
throw new IndexOutOfBoundsException(); throw new IndexOutOfBoundsException();
} }

View File

@ -26,6 +26,7 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import static io.netty.util.internal.ObjectUtil.checkPositiveOrZero;
import static java.lang.Math.max; import static java.lang.Math.max;
abstract class PoolArena<T> implements PoolArenaMetric { abstract class PoolArena<T> implements PoolArenaMetric {
@ -330,9 +331,7 @@ abstract class PoolArena<T> implements PoolArenaMetric {
} }
int normalizeCapacity(int reqCapacity) { int normalizeCapacity(int reqCapacity) {
if (reqCapacity < 0) { checkPositiveOrZero(reqCapacity, "reqCapacity");
throw new IllegalArgumentException("capacity: " + reqCapacity + " (expected: 0+)");
}
if (reqCapacity >= chunkSize) { if (reqCapacity >= chunkSize) {
return directMemoryCacheAlignment == 0 ? reqCapacity : alignCapacity(reqCapacity); return directMemoryCacheAlignment == 0 ? reqCapacity : alignCapacity(reqCapacity);

View File

@ -17,6 +17,8 @@
package io.netty.buffer; package io.netty.buffer;
import static io.netty.util.internal.ObjectUtil.checkPositiveOrZero;
import io.netty.buffer.PoolArena.SizeClass; import io.netty.buffer.PoolArena.SizeClass;
import io.netty.util.Recycler; import io.netty.util.Recycler;
import io.netty.util.Recycler.Handle; import io.netty.util.Recycler.Handle;
@ -65,10 +67,7 @@ final class PoolThreadCache {
PoolThreadCache(PoolArena<byte[]> heapArena, PoolArena<ByteBuffer> directArena, PoolThreadCache(PoolArena<byte[]> heapArena, PoolArena<ByteBuffer> directArena,
int tinyCacheSize, int smallCacheSize, int normalCacheSize, int tinyCacheSize, int smallCacheSize, int normalCacheSize,
int maxCachedBufferCapacity, int freeSweepAllocationThreshold) { int maxCachedBufferCapacity, int freeSweepAllocationThreshold) {
if (maxCachedBufferCapacity < 0) { checkPositiveOrZero(maxCachedBufferCapacity, "maxCachedBufferCapacity");
throw new IllegalArgumentException("maxCachedBufferCapacity: "
+ maxCachedBufferCapacity + " (expected: >= 0)");
}
this.freeSweepAllocationThreshold = freeSweepAllocationThreshold; this.freeSweepAllocationThreshold = freeSweepAllocationThreshold;
this.heapArena = heapArena; this.heapArena = heapArena;
this.directArena = directArena; this.directArena = directArena;

View File

@ -16,6 +16,8 @@
package io.netty.buffer; package io.netty.buffer;
import static io.netty.util.internal.ObjectUtil.checkPositiveOrZero;
import io.netty.util.NettyRuntime; import io.netty.util.NettyRuntime;
import io.netty.util.concurrent.FastThreadLocal; import io.netty.util.concurrent.FastThreadLocal;
import io.netty.util.concurrent.FastThreadLocalThread; import io.netty.util.concurrent.FastThreadLocalThread;
@ -215,17 +217,10 @@ public class PooledByteBufAllocator extends AbstractByteBufAllocator implements
this.normalCacheSize = normalCacheSize; this.normalCacheSize = normalCacheSize;
chunkSize = validateAndCalculateChunkSize(pageSize, maxOrder); chunkSize = validateAndCalculateChunkSize(pageSize, maxOrder);
if (nHeapArena < 0) { checkPositiveOrZero(nHeapArena, "nHeapArena");
throw new IllegalArgumentException("nHeapArena: " + nHeapArena + " (expected: >= 0)"); checkPositiveOrZero(nDirectArena, "nDirectArena");
}
if (nDirectArena < 0) {
throw new IllegalArgumentException("nDirectArea: " + nDirectArena + " (expected: >= 0)");
}
if (directMemoryCacheAlignment < 0) { checkPositiveOrZero(directMemoryCacheAlignment, "directMemoryCacheAlignment");
throw new IllegalArgumentException("directMemoryCacheAlignment: "
+ directMemoryCacheAlignment + " (expected: >= 0)");
}
if (directMemoryCacheAlignment > 0 && !isDirectMemoryCacheAlignmentSupported()) { if (directMemoryCacheAlignment > 0 && !isDirectMemoryCacheAlignmentSupported()) {
throw new IllegalArgumentException("directMemoryCacheAlignment is not supported"); throw new IllegalArgumentException("directMemoryCacheAlignment is not supported");
} }

View File

@ -15,6 +15,8 @@
*/ */
package io.netty.buffer; package io.netty.buffer;
import static io.netty.util.internal.ObjectUtil.checkPositiveOrZero;
import io.netty.util.internal.PlatformDependent; import io.netty.util.internal.PlatformDependent;
import java.io.IOException; import java.io.IOException;
@ -52,12 +54,8 @@ public class UnpooledDirectByteBuf extends AbstractReferenceCountedByteBuf {
if (alloc == null) { if (alloc == null) {
throw new NullPointerException("alloc"); throw new NullPointerException("alloc");
} }
if (initialCapacity < 0) { checkPositiveOrZero(initialCapacity, "initialCapacity");
throw new IllegalArgumentException("initialCapacity: " + initialCapacity); checkPositiveOrZero(maxCapacity, "maxCapacity");
}
if (maxCapacity < 0) {
throw new IllegalArgumentException("maxCapacity: " + maxCapacity);
}
if (initialCapacity > maxCapacity) { if (initialCapacity > maxCapacity) {
throw new IllegalArgumentException(String.format( throw new IllegalArgumentException(String.format(
"initialCapacity(%d) > maxCapacity(%d)", initialCapacity, maxCapacity)); "initialCapacity(%d) > maxCapacity(%d)", initialCapacity, maxCapacity));

View File

@ -15,6 +15,8 @@
*/ */
package io.netty.buffer; package io.netty.buffer;
import static io.netty.util.internal.ObjectUtil.checkPositiveOrZero;
import io.netty.util.internal.PlatformDependent; import io.netty.util.internal.PlatformDependent;
import java.io.IOException; import java.io.IOException;
@ -53,12 +55,8 @@ public class UnpooledUnsafeDirectByteBuf extends AbstractReferenceCountedByteBuf
if (alloc == null) { if (alloc == null) {
throw new NullPointerException("alloc"); throw new NullPointerException("alloc");
} }
if (initialCapacity < 0) { checkPositiveOrZero(initialCapacity, "initialCapacity");
throw new IllegalArgumentException("initialCapacity: " + initialCapacity); checkPositiveOrZero(maxCapacity, "maxCapacity");
}
if (maxCapacity < 0) {
throw new IllegalArgumentException("maxCapacity: " + maxCapacity);
}
if (initialCapacity > maxCapacity) { if (initialCapacity > maxCapacity) {
throw new IllegalArgumentException(String.format( throw new IllegalArgumentException(String.format(
"initialCapacity(%d) > maxCapacity(%d)", initialCapacity, maxCapacity)); "initialCapacity(%d) > maxCapacity(%d)", initialCapacity, maxCapacity));

View File

@ -15,6 +15,8 @@
*/ */
package io.netty.handler.codec; package io.netty.handler.codec;
import static io.netty.util.internal.ObjectUtil.checkPositive;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator; import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.CompositeByteBuf; import io.netty.buffer.CompositeByteBuf;
@ -202,9 +204,7 @@ public abstract class ByteToMessageDecoder extends ChannelInboundHandlerAdapter
* The default is {@code 16}. * The default is {@code 16}.
*/ */
public void setDiscardAfterReads(int discardAfterReads) { public void setDiscardAfterReads(int discardAfterReads) {
if (discardAfterReads <= 0) { checkPositive(discardAfterReads, "discardAfterReads");
throw new IllegalArgumentException("discardAfterReads must be > 0");
}
this.discardAfterReads = discardAfterReads; this.discardAfterReads = discardAfterReads;
} }

View File

@ -15,6 +15,8 @@
*/ */
package io.netty.handler.codec; package io.netty.handler.codec;
import static io.netty.util.internal.ObjectUtil.checkPositive;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
@ -346,10 +348,6 @@ public class DelimiterBasedFrameDecoder extends ByteToMessageDecoder {
} }
private static void validateMaxFrameLength(int maxFrameLength) { private static void validateMaxFrameLength(int maxFrameLength) {
if (maxFrameLength <= 0) { checkPositive(maxFrameLength, "maxFrameLength");
throw new IllegalArgumentException(
"maxFrameLength must be a positive integer: " +
maxFrameLength);
}
} }
} }

View File

@ -15,6 +15,8 @@
*/ */
package io.netty.handler.codec; package io.netty.handler.codec;
import static io.netty.util.internal.ObjectUtil.checkPositive;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
@ -46,10 +48,7 @@ public class FixedLengthFrameDecoder extends ByteToMessageDecoder {
* @param frameLength the length of the frame * @param frameLength the length of the frame
*/ */
public FixedLengthFrameDecoder(int frameLength) { public FixedLengthFrameDecoder(int frameLength) {
if (frameLength <= 0) { checkPositive(frameLength, "frameLength");
throw new IllegalArgumentException(
"frameLength must be a positive integer: " + frameLength);
}
this.frameLength = frameLength; this.frameLength = frameLength;
} }

View File

@ -15,6 +15,9 @@
*/ */
package io.netty.handler.codec; package io.netty.handler.codec;
import static io.netty.util.internal.ObjectUtil.checkPositive;
import static io.netty.util.internal.ObjectUtil.checkPositiveOrZero;
import java.nio.ByteOrder; import java.nio.ByteOrder;
import java.util.List; import java.util.List;
@ -302,23 +305,11 @@ public class LengthFieldBasedFrameDecoder extends ByteToMessageDecoder {
throw new NullPointerException("byteOrder"); throw new NullPointerException("byteOrder");
} }
if (maxFrameLength <= 0) { checkPositive(maxFrameLength, "maxFrameLength");
throw new IllegalArgumentException(
"maxFrameLength must be a positive integer: " +
maxFrameLength);
}
if (lengthFieldOffset < 0) { checkPositiveOrZero(lengthFieldOffset, "lengthFieldOffset");
throw new IllegalArgumentException(
"lengthFieldOffset must be a non-negative integer: " +
lengthFieldOffset);
}
if (initialBytesToStrip < 0) { checkPositiveOrZero(initialBytesToStrip, "initialBytesToStrip");
throw new IllegalArgumentException(
"initialBytesToStrip must be a non-negative integer: " +
initialBytesToStrip);
}
if (lengthFieldOffset > maxFrameLength - lengthFieldLength) { if (lengthFieldOffset > maxFrameLength - lengthFieldLength) {
throw new IllegalArgumentException( throw new IllegalArgumentException(

View File

@ -15,6 +15,8 @@
*/ */
package io.netty.handler.codec; package io.netty.handler.codec;
import static io.netty.util.internal.ObjectUtil.checkPositiveOrZero;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandler.Sharable; import io.netty.channel.ChannelHandler.Sharable;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
@ -163,10 +165,7 @@ public class LengthFieldPrepender extends MessageToMessageEncoder<ByteBuf> {
length += lengthFieldLength; length += lengthFieldLength;
} }
if (length < 0) { checkPositiveOrZero(length, "length");
throw new IllegalArgumentException(
"Adjusted frame length (" + length + ") is less than zero");
}
switch (lengthFieldLength) { switch (lengthFieldLength) {
case 1: case 1:

View File

@ -28,6 +28,7 @@ import io.netty.util.ReferenceCountUtil;
import java.util.List; import java.util.List;
import static io.netty.buffer.Unpooled.EMPTY_BUFFER; import static io.netty.buffer.Unpooled.EMPTY_BUFFER;
import static io.netty.util.internal.ObjectUtil.checkPositiveOrZero;
/** /**
* An abstract {@link ChannelHandler} that aggregates a series of message objects into a single aggregated message. * An abstract {@link ChannelHandler} that aggregates a series of message objects into a single aggregated message.
@ -81,9 +82,7 @@ public abstract class MessageAggregator<I, S, C extends ByteBufHolder, O extends
} }
private static void validateMaxContentLength(int maxContentLength) { private static void validateMaxContentLength(int maxContentLength) {
if (maxContentLength < 0) { checkPositiveOrZero(maxContentLength, "maxContentLength");
throw new IllegalArgumentException("maxContentLength: " + maxContentLength + " (expected: >= 0)");
}
} }
@Override @Override

View File

@ -16,6 +16,8 @@
package io.netty.testsuite.http2; package io.netty.testsuite.http2;
import static io.netty.util.internal.ObjectUtil.checkPositiveOrZero;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelInitializer;
@ -59,9 +61,7 @@ public class Http2ServerInitializer extends ChannelInitializer<SocketChannel> {
} }
Http2ServerInitializer(int maxHttpContentLength) { Http2ServerInitializer(int maxHttpContentLength) {
if (maxHttpContentLength < 0) { checkPositiveOrZero(maxHttpContentLength, "maxHttpContentLength");
throw new IllegalArgumentException("maxHttpContentLength (expected >= 0): " + maxHttpContentLength);
}
this.maxHttpContentLength = maxHttpContentLength; this.maxHttpContentLength = maxHttpContentLength;
} }

View File

@ -54,6 +54,7 @@ import static io.netty.channel.internal.ChannelUtils.MAX_BYTES_PER_GATHERING_WRI
import static io.netty.channel.internal.ChannelUtils.WRITE_STATUS_SNDBUF_FULL; import static io.netty.channel.internal.ChannelUtils.WRITE_STATUS_SNDBUF_FULL;
import static io.netty.channel.unix.FileDescriptor.pipe; import static io.netty.channel.unix.FileDescriptor.pipe;
import static io.netty.util.internal.ObjectUtil.checkNotNull; import static io.netty.util.internal.ObjectUtil.checkNotNull;
import static io.netty.util.internal.ObjectUtil.checkPositiveOrZero;
public abstract class AbstractEpollStreamChannel extends AbstractEpollChannel implements DuplexChannel { public abstract class AbstractEpollStreamChannel extends AbstractEpollChannel implements DuplexChannel {
private static final ChannelMetadata METADATA = new ChannelMetadata(false, 16); private static final ChannelMetadata METADATA = new ChannelMetadata(false, 16);
@ -163,9 +164,7 @@ public abstract class AbstractEpollStreamChannel extends AbstractEpollChannel im
if (ch.eventLoop() != eventLoop()) { if (ch.eventLoop() != eventLoop()) {
throw new IllegalArgumentException("EventLoops are not the same."); throw new IllegalArgumentException("EventLoops are not the same.");
} }
if (len < 0) { checkPositiveOrZero(len, "len");
throw new IllegalArgumentException("len: " + len + " (expected: >= 0)");
}
if (ch.config().getEpollMode() != EpollMode.LEVEL_TRIGGERED if (ch.config().getEpollMode() != EpollMode.LEVEL_TRIGGERED
|| config().getEpollMode() != EpollMode.LEVEL_TRIGGERED) { || config().getEpollMode() != EpollMode.LEVEL_TRIGGERED) {
throw new IllegalStateException("spliceTo() supported only when using " + EpollMode.LEVEL_TRIGGERED); throw new IllegalStateException("spliceTo() supported only when using " + EpollMode.LEVEL_TRIGGERED);
@ -214,12 +213,8 @@ public abstract class AbstractEpollStreamChannel extends AbstractEpollChannel im
*/ */
public final ChannelFuture spliceTo(final FileDescriptor ch, final int offset, final int len, public final ChannelFuture spliceTo(final FileDescriptor ch, final int offset, final int len,
final ChannelPromise promise) { final ChannelPromise promise) {
if (len < 0) { checkPositiveOrZero(len, "len");
throw new IllegalArgumentException("len: " + len + " (expected: >= 0)"); checkPositiveOrZero(offset, "offser");
}
if (offset < 0) {
throw new IllegalArgumentException("offset must be >= 0 but was " + offset);
}
if (config().getEpollMode() != EpollMode.LEVEL_TRIGGERED) { if (config().getEpollMode() != EpollMode.LEVEL_TRIGGERED) {
throw new IllegalStateException("spliceTo() supported only when using " + EpollMode.LEVEL_TRIGGERED); throw new IllegalStateException("spliceTo() supported only when using " + EpollMode.LEVEL_TRIGGERED);
} }

View File

@ -30,6 +30,7 @@ import java.util.Map;
import static io.netty.channel.ChannelOption.SO_BACKLOG; import static io.netty.channel.ChannelOption.SO_BACKLOG;
import static io.netty.channel.ChannelOption.SO_RCVBUF; import static io.netty.channel.ChannelOption.SO_RCVBUF;
import static io.netty.channel.ChannelOption.SO_REUSEADDR; import static io.netty.channel.ChannelOption.SO_REUSEADDR;
import static io.netty.util.internal.ObjectUtil.checkPositiveOrZero;
public class EpollServerChannelConfig extends EpollChannelConfig implements ServerSocketChannelConfig { public class EpollServerChannelConfig extends EpollChannelConfig implements ServerSocketChannelConfig {
private volatile int backlog = NetUtil.SOMAXCONN; private volatile int backlog = NetUtil.SOMAXCONN;
@ -120,9 +121,7 @@ public class EpollServerChannelConfig extends EpollChannelConfig implements Serv
} }
public EpollServerChannelConfig setBacklog(int backlog) { public EpollServerChannelConfig setBacklog(int backlog) {
if (backlog < 0) { checkPositiveOrZero(backlog, "backlog");
throw new IllegalArgumentException("backlog: " + backlog);
}
this.backlog = backlog; this.backlog = backlog;
return this; return this;
} }
@ -146,9 +145,7 @@ public class EpollServerChannelConfig extends EpollChannelConfig implements Serv
* @see <a href="https://tools.ietf.org/html/rfc7413">RFC 7413 TCP FastOpen</a> * @see <a href="https://tools.ietf.org/html/rfc7413">RFC 7413 TCP FastOpen</a>
*/ */
public EpollServerChannelConfig setTcpFastopen(int pendingFastOpenRequestsThreshold) { public EpollServerChannelConfig setTcpFastopen(int pendingFastOpenRequestsThreshold) {
if (this.pendingFastOpenRequestsThreshold < 0) { checkPositiveOrZero(this.pendingFastOpenRequestsThreshold, "pendingFastOpenRequestsThreshold");
throw new IllegalArgumentException("pendingFastOpenRequestsThreshold: " + pendingFastOpenRequestsThreshold);
}
this.pendingFastOpenRequestsThreshold = pendingFastOpenRequestsThreshold; this.pendingFastOpenRequestsThreshold = pendingFastOpenRequestsThreshold;
return this; return this;
} }

View File

@ -31,6 +31,7 @@ import java.util.Map;
import static io.netty.channel.ChannelOption.SO_BACKLOG; import static io.netty.channel.ChannelOption.SO_BACKLOG;
import static io.netty.channel.ChannelOption.SO_RCVBUF; import static io.netty.channel.ChannelOption.SO_RCVBUF;
import static io.netty.channel.ChannelOption.SO_REUSEADDR; import static io.netty.channel.ChannelOption.SO_REUSEADDR;
import static io.netty.util.internal.ObjectUtil.checkPositiveOrZero;
@UnstableApi @UnstableApi
public class KQueueServerChannelConfig extends KQueueChannelConfig implements ServerSocketChannelConfig { public class KQueueServerChannelConfig extends KQueueChannelConfig implements ServerSocketChannelConfig {
@ -116,9 +117,7 @@ public class KQueueServerChannelConfig extends KQueueChannelConfig implements Se
} }
public KQueueServerChannelConfig setBacklog(int backlog) { public KQueueServerChannelConfig setBacklog(int backlog) {
if (backlog < 0) { checkPositiveOrZero(backlog, "backlog");
throw new IllegalArgumentException("backlog: " + backlog);
}
this.backlog = backlog; this.backlog = backlog;
return this; return this;
} }

View File

@ -27,6 +27,7 @@ import static io.netty.channel.unix.Errors.ioResult;
import static io.netty.channel.unix.Errors.newIOException; import static io.netty.channel.unix.Errors.newIOException;
import static io.netty.channel.unix.Limits.IOV_MAX; import static io.netty.channel.unix.Limits.IOV_MAX;
import static io.netty.util.internal.ObjectUtil.checkNotNull; import static io.netty.util.internal.ObjectUtil.checkNotNull;
import static io.netty.util.internal.ObjectUtil.checkPositiveOrZero;
import static java.lang.Math.min; import static java.lang.Math.min;
/** /**
@ -82,9 +83,7 @@ public class FileDescriptor {
final int fd; final int fd;
public FileDescriptor(int fd) { public FileDescriptor(int fd) {
if (fd < 0) { checkPositiveOrZero(fd, "fd");
throw new IllegalArgumentException("fd must be >= 0");
}
this.fd = fd; this.fd = fd;
} }

View File

@ -15,6 +15,8 @@
*/ */
package io.netty.channel.sctp; package io.netty.channel.sctp;
import static io.netty.util.internal.ObjectUtil.checkPositiveOrZero;
import com.sun.nio.sctp.SctpServerChannel; import com.sun.nio.sctp.SctpServerChannel;
import com.sun.nio.sctp.SctpStandardSocketOptions; import com.sun.nio.sctp.SctpStandardSocketOptions;
import io.netty.buffer.ByteBufAllocator; import io.netty.buffer.ByteBufAllocator;
@ -152,9 +154,7 @@ public class DefaultSctpServerChannelConfig extends DefaultChannelConfig impleme
@Override @Override
public SctpServerChannelConfig setBacklog(int backlog) { public SctpServerChannelConfig setBacklog(int backlog) {
if (backlog < 0) { checkPositiveOrZero(backlog, "backlog");
throw new IllegalArgumentException("backlog: " + backlog);
}
this.backlog = backlog; this.backlog = backlog;
return this; return this;
} }

View File

@ -18,6 +18,7 @@ package io.netty.channel;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import static io.netty.util.internal.ObjectUtil.checkPositive;
import static java.lang.Math.max; import static java.lang.Math.max;
import static java.lang.Math.min; import static java.lang.Math.min;
@ -163,9 +164,7 @@ public class AdaptiveRecvByteBufAllocator extends DefaultMaxMessagesRecvByteBufA
* @param maximum the inclusive upper bound of the expected buffer size * @param maximum the inclusive upper bound of the expected buffer size
*/ */
public AdaptiveRecvByteBufAllocator(int minimum, int initial, int maximum) { public AdaptiveRecvByteBufAllocator(int minimum, int initial, int maximum) {
if (minimum <= 0) { checkPositive(minimum, "minimum");
throw new IllegalArgumentException("minimum: " + minimum);
}
if (initial < minimum) { if (initial < minimum) {
throw new IllegalArgumentException("initial: " + initial); throw new IllegalArgumentException("initial: " + initial);
} }

View File

@ -15,6 +15,8 @@
*/ */
package io.netty.channel; package io.netty.channel;
import static io.netty.util.internal.ObjectUtil.checkPositiveOrZero;
import java.util.ArrayDeque; import java.util.ArrayDeque;
import java.util.Queue; import java.util.Queue;
@ -64,9 +66,7 @@ public final class ChannelFlushPromiseNotifier {
if (promise == null) { if (promise == null) {
throw new NullPointerException("promise"); throw new NullPointerException("promise");
} }
if (pendingDataSize < 0) { checkPositiveOrZero(pendingDataSize, "pendingDataSize");
throw new IllegalArgumentException("pendingDataSize must be >= 0 but was " + pendingDataSize);
}
long checkpoint = writeCounter + pendingDataSize; long checkpoint = writeCounter + pendingDataSize;
if (promise instanceof FlushCheckpoint) { if (promise instanceof FlushCheckpoint) {
FlushCheckpoint cp = (FlushCheckpoint) promise; FlushCheckpoint cp = (FlushCheckpoint) promise;
@ -81,9 +81,7 @@ public final class ChannelFlushPromiseNotifier {
* Increase the current write counter by the given delta * Increase the current write counter by the given delta
*/ */
public ChannelFlushPromiseNotifier increaseWriteCounter(long delta) { public ChannelFlushPromiseNotifier increaseWriteCounter(long delta) {
if (delta < 0) { checkPositiveOrZero(delta, "delta");
throw new IllegalArgumentException("delta must be >= 0 but was " + delta);
}
writeCounter += delta; writeCounter += delta;
return this; return this;
} }

View File

@ -15,6 +15,8 @@
*/ */
package io.netty.channel; package io.netty.channel;
import static io.netty.util.internal.ObjectUtil.checkPositive;
import java.net.SocketAddress; import java.net.SocketAddress;
/** /**
@ -46,10 +48,7 @@ public final class ChannelMetadata {
* set for {@link MaxMessagesRecvByteBufAllocator#maxMessagesPerRead()}. Must be {@code > 0}. * set for {@link MaxMessagesRecvByteBufAllocator#maxMessagesPerRead()}. Must be {@code > 0}.
*/ */
public ChannelMetadata(boolean hasDisconnect, int defaultMaxMessagesPerRead) { public ChannelMetadata(boolean hasDisconnect, int defaultMaxMessagesPerRead) {
if (defaultMaxMessagesPerRead <= 0) { checkPositive(defaultMaxMessagesPerRead, "defaultMaxMessagesPerRead");
throw new IllegalArgumentException("defaultMaxMessagesPerRead: " + defaultMaxMessagesPerRead +
" (expected > 0)");
}
this.hasDisconnect = hasDisconnect; this.hasDisconnect = hasDisconnect;
this.defaultMaxMessagesPerRead = defaultMaxMessagesPerRead; this.defaultMaxMessagesPerRead = defaultMaxMessagesPerRead;
} }

View File

@ -36,6 +36,8 @@ import static io.netty.channel.ChannelOption.WRITE_BUFFER_LOW_WATER_MARK;
import static io.netty.channel.ChannelOption.WRITE_BUFFER_WATER_MARK; import static io.netty.channel.ChannelOption.WRITE_BUFFER_WATER_MARK;
import static io.netty.channel.ChannelOption.WRITE_SPIN_COUNT; import static io.netty.channel.ChannelOption.WRITE_SPIN_COUNT;
import static io.netty.util.internal.ObjectUtil.checkNotNull; import static io.netty.util.internal.ObjectUtil.checkNotNull;
import static io.netty.util.internal.ObjectUtil.checkPositive;
import static io.netty.util.internal.ObjectUtil.checkPositiveOrZero;
/** /**
* The default {@link ChannelConfig} implementation. * The default {@link ChannelConfig} implementation.
@ -209,10 +211,7 @@ public class DefaultChannelConfig implements ChannelConfig {
@Override @Override
public ChannelConfig setConnectTimeoutMillis(int connectTimeoutMillis) { public ChannelConfig setConnectTimeoutMillis(int connectTimeoutMillis) {
if (connectTimeoutMillis < 0) { checkPositiveOrZero(connectTimeoutMillis, "connectTimeoutMillis");
throw new IllegalArgumentException(String.format(
"connectTimeoutMillis: %d (expected: >= 0)", connectTimeoutMillis));
}
this.connectTimeoutMillis = connectTimeoutMillis; this.connectTimeoutMillis = connectTimeoutMillis;
return this; return this;
} }
@ -261,10 +260,7 @@ public class DefaultChannelConfig implements ChannelConfig {
@Override @Override
public ChannelConfig setWriteSpinCount(int writeSpinCount) { public ChannelConfig setWriteSpinCount(int writeSpinCount) {
if (writeSpinCount <= 0) { checkPositive(writeSpinCount, "writeSpinCount");
throw new IllegalArgumentException(
"writeSpinCount must be a positive integer.");
}
// Integer.MAX_VALUE is used as a special value in the channel implementations to indicate the channel cannot // Integer.MAX_VALUE is used as a special value in the channel implementations to indicate the channel cannot
// accept any more data, and results in the writeOp being set on the selector (or execute a runnable which tries // accept any more data, and results in the writeOp being set on the selector (or execute a runnable which tries
// to flush later because the writeSpinCount quantum has been exhausted). This strategy prevents additional // to flush later because the writeSpinCount quantum has been exhausted). This strategy prevents additional
@ -357,10 +353,7 @@ public class DefaultChannelConfig implements ChannelConfig {
@Override @Override
public ChannelConfig setWriteBufferHighWaterMark(int writeBufferHighWaterMark) { public ChannelConfig setWriteBufferHighWaterMark(int writeBufferHighWaterMark) {
if (writeBufferHighWaterMark < 0) { checkPositiveOrZero(writeBufferHighWaterMark, "writeBufferHighWaterMark");
throw new IllegalArgumentException(
"writeBufferHighWaterMark must be >= 0");
}
for (;;) { for (;;) {
WriteBufferWaterMark waterMark = writeBufferWaterMark; WriteBufferWaterMark waterMark = writeBufferWaterMark;
if (writeBufferHighWaterMark < waterMark.low()) { if (writeBufferHighWaterMark < waterMark.low()) {
@ -383,10 +376,7 @@ public class DefaultChannelConfig implements ChannelConfig {
@Override @Override
public ChannelConfig setWriteBufferLowWaterMark(int writeBufferLowWaterMark) { public ChannelConfig setWriteBufferLowWaterMark(int writeBufferLowWaterMark) {
if (writeBufferLowWaterMark < 0) { checkPositiveOrZero(writeBufferLowWaterMark, "writeBufferLowWaterMark");
throw new IllegalArgumentException(
"writeBufferLowWaterMark must be >= 0");
}
for (;;) { for (;;) {
WriteBufferWaterMark waterMark = writeBufferWaterMark; WriteBufferWaterMark waterMark = writeBufferWaterMark;
if (writeBufferLowWaterMark > waterMark.high()) { if (writeBufferLowWaterMark > waterMark.high()) {

View File

@ -15,6 +15,8 @@
*/ */
package io.netty.channel; package io.netty.channel;
import static io.netty.util.internal.ObjectUtil.checkPositiveOrZero;
import io.netty.util.AbstractReferenceCounted; import io.netty.util.AbstractReferenceCounted;
import io.netty.util.IllegalReferenceCountException; import io.netty.util.IllegalReferenceCountException;
import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLogger;
@ -52,12 +54,8 @@ public class DefaultFileRegion extends AbstractReferenceCounted implements FileR
if (file == null) { if (file == null) {
throw new NullPointerException("file"); throw new NullPointerException("file");
} }
if (position < 0) { checkPositiveOrZero(position, "position");
throw new IllegalArgumentException("position must be >= 0 but was " + position); checkPositiveOrZero(count, "count");
}
if (count < 0) {
throw new IllegalArgumentException("count must be >= 0 but was " + count);
}
this.file = file; this.file = file;
this.position = position; this.position = position;
this.count = count; this.count = count;
@ -76,12 +74,8 @@ public class DefaultFileRegion extends AbstractReferenceCounted implements FileR
if (f == null) { if (f == null) {
throw new NullPointerException("f"); throw new NullPointerException("f");
} }
if (position < 0) { checkPositiveOrZero(position, "position");
throw new IllegalArgumentException("position must be >= 0 but was " + position); checkPositiveOrZero(count, "count");
}
if (count < 0) {
throw new IllegalArgumentException("count must be >= 0 but was " + count);
}
this.position = position; this.position = position;
this.count = count; this.count = count;
this.f = f; this.f = f;

View File

@ -15,6 +15,8 @@
*/ */
package io.netty.channel; package io.netty.channel;
import static io.netty.util.internal.ObjectUtil.checkPositive;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator; import io.netty.buffer.ByteBufAllocator;
import io.netty.util.UncheckedBooleanSupplier; import io.netty.util.UncheckedBooleanSupplier;
@ -124,9 +126,7 @@ public class DefaultMaxBytesRecvByteBufAllocator implements MaxBytesRecvByteBufA
@Override @Override
public DefaultMaxBytesRecvByteBufAllocator maxBytesPerRead(int maxBytesPerRead) { public DefaultMaxBytesRecvByteBufAllocator maxBytesPerRead(int maxBytesPerRead) {
if (maxBytesPerRead <= 0) { checkPositive(maxBytesPerRead, "maxBytesPerRead");
throw new IllegalArgumentException("maxBytesPerRead: " + maxBytesPerRead + " (expected: > 0)");
}
// There is a dependency between this.maxBytesPerRead and this.maxBytesPerIndividualRead (a < b). // There is a dependency between this.maxBytesPerRead and this.maxBytesPerIndividualRead (a < b).
// Write operations must be synchronized, but independent read operations can just be volatile. // Write operations must be synchronized, but independent read operations can just be volatile.
synchronized (this) { synchronized (this) {
@ -149,10 +149,7 @@ public class DefaultMaxBytesRecvByteBufAllocator implements MaxBytesRecvByteBufA
@Override @Override
public DefaultMaxBytesRecvByteBufAllocator maxBytesPerIndividualRead(int maxBytesPerIndividualRead) { public DefaultMaxBytesRecvByteBufAllocator maxBytesPerIndividualRead(int maxBytesPerIndividualRead) {
if (maxBytesPerIndividualRead <= 0) { checkPositive(maxBytesPerIndividualRead, "maxBytesPerIndividualRead");
throw new IllegalArgumentException(
"maxBytesPerIndividualRead: " + maxBytesPerIndividualRead + " (expected: > 0)");
}
// There is a dependency between this.maxBytesPerRead and this.maxBytesPerIndividualRead (a < b). // There is a dependency between this.maxBytesPerRead and this.maxBytesPerIndividualRead (a < b).
// Write operations must be synchronized, but independent read operations can just be volatile. // Write operations must be synchronized, but independent read operations can just be volatile.
synchronized (this) { synchronized (this) {
@ -174,13 +171,8 @@ public class DefaultMaxBytesRecvByteBufAllocator implements MaxBytesRecvByteBufA
} }
private static void checkMaxBytesPerReadPair(int maxBytesPerRead, int maxBytesPerIndividualRead) { private static void checkMaxBytesPerReadPair(int maxBytesPerRead, int maxBytesPerIndividualRead) {
if (maxBytesPerRead <= 0) { checkPositive(maxBytesPerRead, "maxBytesPerRead");
throw new IllegalArgumentException("maxBytesPerRead: " + maxBytesPerRead + " (expected: > 0)"); checkPositive(maxBytesPerIndividualRead, "maxBytesPerIndividualRead");
}
if (maxBytesPerIndividualRead <= 0) {
throw new IllegalArgumentException(
"maxBytesPerIndividualRead: " + maxBytesPerIndividualRead + " (expected: > 0)");
}
if (maxBytesPerRead < maxBytesPerIndividualRead) { if (maxBytesPerRead < maxBytesPerIndividualRead) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"maxBytesPerRead cannot be less than " + "maxBytesPerRead cannot be less than " +

View File

@ -15,6 +15,8 @@
*/ */
package io.netty.channel; package io.netty.channel;
import static io.netty.util.internal.ObjectUtil.checkPositive;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator; import io.netty.buffer.ByteBufAllocator;
import io.netty.util.UncheckedBooleanSupplier; import io.netty.util.UncheckedBooleanSupplier;
@ -42,9 +44,7 @@ public abstract class DefaultMaxMessagesRecvByteBufAllocator implements MaxMessa
@Override @Override
public MaxMessagesRecvByteBufAllocator maxMessagesPerRead(int maxMessagesPerRead) { public MaxMessagesRecvByteBufAllocator maxMessagesPerRead(int maxMessagesPerRead) {
if (maxMessagesPerRead <= 0) { checkPositive(maxMessagesPerRead, "maxMessagesPerRead");
throw new IllegalArgumentException("maxMessagesPerRead: " + maxMessagesPerRead + " (expected: > 0)");
}
this.maxMessagesPerRead = maxMessagesPerRead; this.maxMessagesPerRead = maxMessagesPerRead;
return this; return this;
} }

View File

@ -15,6 +15,8 @@
*/ */
package io.netty.channel; package io.netty.channel;
import static io.netty.util.internal.ObjectUtil.checkPositiveOrZero;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufHolder; import io.netty.buffer.ByteBufHolder;
@ -59,9 +61,7 @@ public final class DefaultMessageSizeEstimator implements MessageSizeEstimator {
* @param unknownSize The size which is returned for unknown messages. * @param unknownSize The size which is returned for unknown messages.
*/ */
public DefaultMessageSizeEstimator(int unknownSize) { public DefaultMessageSizeEstimator(int unknownSize) {
if (unknownSize < 0) { checkPositiveOrZero(unknownSize, "unknownSize");
throw new IllegalArgumentException("unknownSize: " + unknownSize + " (expected: >= 0)");
}
handle = new HandleImpl(unknownSize); handle = new HandleImpl(unknownSize);
} }

View File

@ -15,6 +15,8 @@
*/ */
package io.netty.channel; package io.netty.channel;
import static io.netty.util.internal.ObjectUtil.checkPositive;
/** /**
* The {@link RecvByteBufAllocator} that always yields the same buffer * The {@link RecvByteBufAllocator} that always yields the same buffer
* size prediction. This predictor ignores the feed back from the I/O thread. * size prediction. This predictor ignores the feed back from the I/O thread.
@ -41,10 +43,7 @@ public class FixedRecvByteBufAllocator extends DefaultMaxMessagesRecvByteBufAllo
* the specified buffer size. * the specified buffer size.
*/ */
public FixedRecvByteBufAllocator(int bufferSize) { public FixedRecvByteBufAllocator(int bufferSize) {
if (bufferSize <= 0) { checkPositive(bufferSize, "bufferSize");
throw new IllegalArgumentException(
"bufferSize must greater than 0: " + bufferSize);
}
this.bufferSize = bufferSize; this.bufferSize = bufferSize;
} }

View File

@ -15,6 +15,8 @@
*/ */
package io.netty.channel; package io.netty.channel;
import static io.netty.util.internal.ObjectUtil.checkPositiveOrZero;
/** /**
* WriteBufferWaterMark is used to set low water mark and high water mark for the write buffer. * WriteBufferWaterMark is used to set low water mark and high water mark for the write buffer.
* <p> * <p>
@ -54,9 +56,7 @@ public final class WriteBufferWaterMark {
*/ */
WriteBufferWaterMark(int low, int high, boolean validate) { WriteBufferWaterMark(int low, int high, boolean validate) {
if (validate) { if (validate) {
if (low < 0) { checkPositiveOrZero(low, "low");
throw new IllegalArgumentException("write buffer's low water mark must be >= 0");
}
if (high < low) { if (high < low) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"write buffer's high water mark cannot be less than " + "write buffer's high water mark cannot be less than " +

View File

@ -31,6 +31,7 @@ import java.util.Map;
import static io.netty.channel.ChannelOption.SO_BACKLOG; import static io.netty.channel.ChannelOption.SO_BACKLOG;
import static io.netty.channel.ChannelOption.SO_RCVBUF; import static io.netty.channel.ChannelOption.SO_RCVBUF;
import static io.netty.channel.ChannelOption.SO_REUSEADDR; import static io.netty.channel.ChannelOption.SO_REUSEADDR;
import static io.netty.util.internal.ObjectUtil.checkPositiveOrZero;
/** /**
* The default {@link ServerSocketChannelConfig} implementation. * The default {@link ServerSocketChannelConfig} implementation.
@ -141,9 +142,7 @@ public class DefaultServerSocketChannelConfig extends DefaultChannelConfig
@Override @Override
public ServerSocketChannelConfig setBacklog(int backlog) { public ServerSocketChannelConfig setBacklog(int backlog) {
if (backlog < 0) { checkPositiveOrZero(backlog, "backlog");
throw new IllegalArgumentException("backlog: " + backlog);
}
this.backlog = backlog; this.backlog = backlog;
return this; return this;
} }