migrate java8: use requireNonNull (#8840)

Motivation:

We can just use Objects.requireNonNull(...) as a replacement for ObjectUtil.checkNotNull(....)

Modifications:

- Use Objects.requireNonNull(...)

Result:

Less code to maintain.
This commit is contained in:
田欧 2019-02-04 17:32:25 +08:00 committed by Norman Maurer
parent 2e433889b2
commit e8efcd82a8
369 changed files with 1390 additions and 1734 deletions

View File

@ -39,6 +39,7 @@ 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; import static io.netty.util.internal.ObjectUtil.checkPositiveOrZero;
import static java.util.Objects.requireNonNull;
/** /**
* A skeletal implementation of a buffer. * A skeletal implementation of a buffer.
@ -282,9 +283,7 @@ public abstract class AbstractByteBuf extends ByteBuf {
if (endianness == order()) { if (endianness == order()) {
return this; return this;
} }
if (endianness == null) { requireNonNull(endianness, "endianness");
throw new NullPointerException("endianness");
}
return newSwappedByteBuf(); return newSwappedByteBuf();
} }
@ -592,9 +591,7 @@ public abstract class AbstractByteBuf extends ByteBuf {
@Override @Override
public ByteBuf setBytes(int index, ByteBuf src, int length) { public ByteBuf setBytes(int index, ByteBuf src, int length) {
checkIndex(index, length); checkIndex(index, length);
if (src == null) { requireNonNull(src, "src");
throw new NullPointerException("src");
}
if (checkBounds) { if (checkBounds) {
checkReadableBounds(src, length); checkReadableBounds(src, length);
} }

View File

@ -15,6 +15,8 @@
*/ */
package io.netty.buffer; package io.netty.buffer;
import static java.util.Objects.requireNonNull;
import io.netty.util.ReferenceCounted; import io.netty.util.ReferenceCounted;
import io.netty.util.internal.StringUtil; import io.netty.util.internal.StringUtil;
@ -104,9 +106,7 @@ public class ByteBufInputStream extends InputStream implements DataInput {
* {@code writerIndex} * {@code writerIndex}
*/ */
public ByteBufInputStream(ByteBuf buffer, int length, boolean releaseOnClose) { public ByteBufInputStream(ByteBuf buffer, int length, boolean releaseOnClose) {
if (buffer == null) { requireNonNull(buffer, "buffer");
throw new NullPointerException("buffer");
}
if (length < 0) { if (length < 0) {
if (releaseOnClose) { if (releaseOnClose) {
buffer.release(); buffer.release();

View File

@ -15,6 +15,8 @@
*/ */
package io.netty.buffer; package io.netty.buffer;
import static java.util.Objects.requireNonNull;
import io.netty.util.CharsetUtil; import io.netty.util.CharsetUtil;
import java.io.DataOutput; import java.io.DataOutput;
@ -45,9 +47,7 @@ public class ByteBufOutputStream extends OutputStream implements DataOutput {
* Creates a new stream which writes data to the specified {@code buffer}. * Creates a new stream which writes data to the specified {@code buffer}.
*/ */
public ByteBufOutputStream(ByteBuf buffer) { public ByteBufOutputStream(ByteBuf buffer) {
if (buffer == null) { requireNonNull(buffer, "buffer");
throw new NullPointerException("buffer");
}
this.buffer = buffer; this.buffer = buffer;
startIndex = buffer.writerIndex(); startIndex = buffer.writerIndex();
} }

View File

@ -42,10 +42,10 @@ import java.util.Arrays;
import java.util.Locale; 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.checkPositiveOrZero; 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;
import static java.util.Objects.requireNonNull;
/** /**
* A collection of utility methods that is related with handling {@link ByteBuf}, * A collection of utility methods that is related with handling {@link ByteBuf},
@ -884,7 +884,7 @@ public final class ByteBufUtil {
+ length + ") <= srcLen(" + src.length() + ')'); + length + ") <= srcLen(" + src.length() + ')');
} }
checkNotNull(dst, "dst").setBytes(dstIdx, src.array(), srcIdx + src.arrayOffset(), length); requireNonNull(dst, "dst").setBytes(dstIdx, src.array(), srcIdx + src.arrayOffset(), length);
} }
/** /**
@ -901,7 +901,7 @@ public final class ByteBufUtil {
+ length + ") <= srcLen(" + src.length() + ')'); + length + ") <= srcLen(" + src.length() + ')');
} }
checkNotNull(dst, "dst").writeBytes(src.array(), srcIdx + src.arrayOffset(), length); requireNonNull(dst, "dst").writeBytes(src.array(), srcIdx + src.arrayOffset(), length);
} }
/** /**
@ -1217,8 +1217,8 @@ public final class ByteBufUtil {
* @throws IndexOutOfBoundsException if {@code index} + {@code length} is greater than {@code buf.readableBytes} * @throws IndexOutOfBoundsException if {@code index} + {@code length} is greater than {@code buf.readableBytes}
*/ */
public static boolean isText(ByteBuf buf, int index, int length, Charset charset) { public static boolean isText(ByteBuf buf, int index, int length, Charset charset) {
checkNotNull(buf, "buf"); requireNonNull(buf, "buf");
checkNotNull(charset, "charset"); requireNonNull(charset, "charset");
final int maxIndex = buf.readerIndex() + buf.readableBytes(); final int maxIndex = buf.readerIndex() + buf.readableBytes();
if (index < 0 || length < 0 || index > maxIndex - length) { if (index < 0 || length < 0 || index > maxIndex - length) {
throw new IndexOutOfBoundsException("index: " + index + " length: " + length); throw new IndexOutOfBoundsException("index: " + index + " length: " + length);

View File

@ -15,6 +15,8 @@
*/ */
package io.netty.buffer; package io.netty.buffer;
import static java.util.Objects.requireNonNull;
import io.netty.util.ByteProcessor; import io.netty.util.ByteProcessor;
import io.netty.util.IllegalReferenceCountException; import io.netty.util.IllegalReferenceCountException;
import io.netty.util.ReferenceCountUtil; import io.netty.util.ReferenceCountUtil;
@ -38,7 +40,6 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import static io.netty.util.internal.ObjectUtil.checkNotNull;
/** /**
* A virtual buffer which shows multiple buffers as a single merged buffer. It is recommended to use * A virtual buffer which shows multiple buffers as a single merged buffer. It is recommended to use
@ -61,9 +62,7 @@ public class CompositeByteBuf extends AbstractReferenceCountedByteBuf implements
private CompositeByteBuf(ByteBufAllocator alloc, boolean direct, int maxNumComponents, int initSize) { private CompositeByteBuf(ByteBufAllocator alloc, boolean direct, int maxNumComponents, int initSize) {
super(AbstractByteBufAllocator.DEFAULT_MAX_CAPACITY); super(AbstractByteBufAllocator.DEFAULT_MAX_CAPACITY);
if (alloc == null) { requireNonNull(alloc, "alloc");
throw new NullPointerException("alloc");
}
if (maxNumComponents < 1) { if (maxNumComponents < 1) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"maxNumComponents: " + maxNumComponents + " (expected: >= 1)"); "maxNumComponents: " + maxNumComponents + " (expected: >= 1)");
@ -232,7 +231,7 @@ public class CompositeByteBuf extends AbstractReferenceCountedByteBuf implements
* ownership of all {@link ByteBuf} objects is transferred to this {@link CompositeByteBuf}. * ownership of all {@link ByteBuf} objects is transferred to this {@link CompositeByteBuf}.
*/ */
public CompositeByteBuf addComponents(boolean increaseWriterIndex, ByteBuf... buffers) { public CompositeByteBuf addComponents(boolean increaseWriterIndex, ByteBuf... buffers) {
checkNotNull(buffers, "buffers"); requireNonNull(buffers, "buffers");
addComponents0(increaseWriterIndex, componentCount, buffers, 0); addComponents0(increaseWriterIndex, componentCount, buffers, 0);
consolidateIfNeeded(); consolidateIfNeeded();
return this; return this;
@ -261,7 +260,7 @@ public class CompositeByteBuf extends AbstractReferenceCountedByteBuf implements
* {@link CompositeByteBuf}. * {@link CompositeByteBuf}.
*/ */
public CompositeByteBuf addComponent(boolean increaseWriterIndex, int cIndex, ByteBuf buffer) { public CompositeByteBuf addComponent(boolean increaseWriterIndex, int cIndex, ByteBuf buffer) {
checkNotNull(buffer, "buffer"); requireNonNull(buffer, "buffer");
addComponent0(increaseWriterIndex, cIndex, buffer); addComponent0(increaseWriterIndex, cIndex, buffer);
consolidateIfNeeded(); consolidateIfNeeded();
return this; return this;
@ -333,7 +332,7 @@ public class CompositeByteBuf extends AbstractReferenceCountedByteBuf implements
* ownership of all {@link ByteBuf} objects is transferred to this {@link CompositeByteBuf}. * ownership of all {@link ByteBuf} objects is transferred to this {@link CompositeByteBuf}.
*/ */
public CompositeByteBuf addComponents(int cIndex, ByteBuf... buffers) { public CompositeByteBuf addComponents(int cIndex, ByteBuf... buffers) {
checkNotNull(buffers, "buffers"); requireNonNull(buffers, "buffers");
addComponents0(false, cIndex, buffers, 0); addComponents0(false, cIndex, buffers, 0);
consolidateIfNeeded(); consolidateIfNeeded();
return this; return this;
@ -422,7 +421,7 @@ public class CompositeByteBuf extends AbstractReferenceCountedByteBuf implements
// If buffers also implements ByteBuf (e.g. CompositeByteBuf), it has to go to addComponent(ByteBuf). // If buffers also implements ByteBuf (e.g. CompositeByteBuf), it has to go to addComponent(ByteBuf).
return addComponent(increaseIndex, cIndex, (ByteBuf) buffers); return addComponent(increaseIndex, cIndex, (ByteBuf) buffers);
} }
checkNotNull(buffers, "buffers"); requireNonNull(buffers, "buffers");
Iterator<ByteBuf> it = buffers.iterator(); Iterator<ByteBuf> it = buffers.iterator();
try { try {
checkComponentIndex(cIndex); checkComponentIndex(cIndex);

View File

@ -15,6 +15,8 @@
*/ */
package io.netty.buffer; package io.netty.buffer;
import static java.util.Objects.requireNonNull;
import io.netty.util.IllegalReferenceCountException; import io.netty.util.IllegalReferenceCountException;
import io.netty.util.internal.StringUtil; import io.netty.util.internal.StringUtil;
@ -27,9 +29,7 @@ public class DefaultByteBufHolder implements ByteBufHolder {
private final ByteBuf data; private final ByteBuf data;
public DefaultByteBufHolder(ByteBuf data) { public DefaultByteBufHolder(ByteBuf data) {
if (data == null) { requireNonNull(data, "data");
throw new NullPointerException("data");
}
this.data = data; this.data = data;
} }

View File

@ -17,6 +17,7 @@
package io.netty.buffer; package io.netty.buffer;
import static io.netty.util.internal.ObjectUtil.checkPositiveOrZero; import static io.netty.util.internal.ObjectUtil.checkPositiveOrZero;
import static java.util.Objects.requireNonNull;
import io.netty.util.ByteProcessor; import io.netty.util.ByteProcessor;
import io.netty.util.internal.EmptyArrays; import io.netty.util.internal.EmptyArrays;
@ -64,9 +65,7 @@ public final class EmptyByteBuf extends ByteBuf {
} }
private EmptyByteBuf(ByteBufAllocator alloc, ByteOrder order) { private EmptyByteBuf(ByteBufAllocator alloc, ByteOrder order) {
if (alloc == null) { requireNonNull(alloc, "alloc");
throw new NullPointerException("alloc");
}
this.alloc = alloc; this.alloc = alloc;
this.order = order; this.order = order;
@ -120,9 +119,7 @@ public final class EmptyByteBuf extends ByteBuf {
@Override @Override
public ByteBuf order(ByteOrder endianness) { public ByteBuf order(ByteOrder endianness) {
if (endianness == null) { requireNonNull(endianness, "endianness");
throw new NullPointerException("endianness");
}
if (endianness == order()) { if (endianness == order()) {
return this; return this;
} }

View File

@ -15,6 +15,8 @@
*/ */
package io.netty.buffer; package io.netty.buffer;
import static java.util.Objects.requireNonNull;
import io.netty.util.internal.StringUtil; import io.netty.util.internal.StringUtil;
import java.io.IOException; import java.io.IOException;
@ -27,7 +29,6 @@ import java.nio.channels.FileChannel;
import java.nio.channels.GatheringByteChannel; import java.nio.channels.GatheringByteChannel;
import java.nio.channels.ScatteringByteChannel; import java.nio.channels.ScatteringByteChannel;
/** /**
* Read-only ByteBuf which wraps a read-only ByteBuffer. * Read-only ByteBuf which wraps a read-only ByteBuffer.
*/ */
@ -209,9 +210,7 @@ class ReadOnlyByteBufferBuf extends AbstractReferenceCountedByteBuf {
@Override @Override
public ByteBuf getBytes(int index, ByteBuffer dst) { public ByteBuf getBytes(int index, ByteBuffer dst) {
checkIndex(index); checkIndex(index);
if (dst == null) { requireNonNull(dst, "dst");
throw new NullPointerException("dst");
}
int bytesToCopy = Math.min(capacity() - index, dst.remaining()); int bytesToCopy = Math.min(capacity() - index, dst.remaining());
ByteBuffer tmpBuf = internalNioBuffer(); ByteBuffer tmpBuf = internalNioBuffer();

View File

@ -16,10 +16,12 @@
package io.netty.buffer; package io.netty.buffer;
import io.netty.util.internal.PlatformDependent; import static java.util.Objects.requireNonNull;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import io.netty.util.internal.PlatformDependent;
/** /**
* Read-only ByteBuf which wraps a read-only direct ByteBuffer and use unsafe for best performance. * Read-only ByteBuf which wraps a read-only direct ByteBuffer and use unsafe for best performance.
@ -62,9 +64,7 @@ final class ReadOnlyUnsafeDirectByteBuf extends ReadOnlyByteBufferBuf {
@Override @Override
public ByteBuf getBytes(int index, ByteBuf dst, int dstIndex, int length) { public ByteBuf getBytes(int index, ByteBuf dst, int dstIndex, int length) {
checkIndex(index, length); checkIndex(index, length);
if (dst == null) { requireNonNull(dst, "dst");
throw new NullPointerException("dst");
}
if (dstIndex < 0 || dstIndex > dst.capacity() - length) { if (dstIndex < 0 || dstIndex > dst.capacity() - length) {
throw new IndexOutOfBoundsException("dstIndex: " + dstIndex); throw new IndexOutOfBoundsException("dstIndex: " + dstIndex);
} }
@ -82,9 +82,7 @@ final class ReadOnlyUnsafeDirectByteBuf extends ReadOnlyByteBufferBuf {
@Override @Override
public ByteBuf getBytes(int index, byte[] dst, int dstIndex, int length) { public ByteBuf getBytes(int index, byte[] dst, int dstIndex, int length) {
checkIndex(index, length); checkIndex(index, length);
if (dst == null) { requireNonNull(dst, "dst");
throw new NullPointerException("dst");
}
if (dstIndex < 0 || dstIndex > dst.length - length) { if (dstIndex < 0 || dstIndex > dst.length - length) {
throw new IndexOutOfBoundsException(String.format( throw new IndexOutOfBoundsException(String.format(
"dstIndex: %d, length: %d (expected: range(0, %d))", dstIndex, length, dst.length)); "dstIndex: %d, length: %d (expected: range(0, %d))", dstIndex, length, dst.length));
@ -99,9 +97,7 @@ final class ReadOnlyUnsafeDirectByteBuf extends ReadOnlyByteBufferBuf {
@Override @Override
public ByteBuf getBytes(int index, ByteBuffer dst) { public ByteBuf getBytes(int index, ByteBuffer dst) {
checkIndex(index); checkIndex(index);
if (dst == null) { requireNonNull(dst, "dst");
throw new NullPointerException("dst");
}
int bytesToCopy = Math.min(capacity() - index, dst.remaining()); int bytesToCopy = Math.min(capacity() - index, dst.remaining());
ByteBuffer tmpBuf = internalNioBuffer(); ByteBuffer tmpBuf = internalNioBuffer();

View File

@ -16,9 +16,10 @@
package io.netty.buffer; package io.netty.buffer;
import static java.util.Objects.requireNonNull;
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.ObjectUtil;
import java.nio.ByteOrder; import java.nio.ByteOrder;
@ -34,8 +35,8 @@ class SimpleLeakAwareByteBuf extends WrappedByteBuf {
SimpleLeakAwareByteBuf(ByteBuf wrapped, ByteBuf trackedByteBuf, ResourceLeakTracker<ByteBuf> leak) { SimpleLeakAwareByteBuf(ByteBuf wrapped, ByteBuf trackedByteBuf, ResourceLeakTracker<ByteBuf> leak) {
super(wrapped); super(wrapped);
this.trackedByteBuf = ObjectUtil.checkNotNull(trackedByteBuf, "trackedByteBuf"); this.trackedByteBuf = requireNonNull(trackedByteBuf, "trackedByteBuf");
this.leak = ObjectUtil.checkNotNull(leak, "leak"); this.leak = requireNonNull(leak, "leak");
} }
SimpleLeakAwareByteBuf(ByteBuf wrapped, ResourceLeakTracker<ByteBuf> leak) { SimpleLeakAwareByteBuf(ByteBuf wrapped, ResourceLeakTracker<ByteBuf> leak) {

View File

@ -15,9 +15,9 @@
*/ */
package io.netty.buffer; package io.netty.buffer;
import static java.util.Objects.requireNonNull;
import io.netty.util.ResourceLeakTracker; import io.netty.util.ResourceLeakTracker;
import io.netty.util.internal.ObjectUtil;
import java.nio.ByteOrder; import java.nio.ByteOrder;
@ -27,7 +27,7 @@ class SimpleLeakAwareCompositeByteBuf extends WrappedCompositeByteBuf {
SimpleLeakAwareCompositeByteBuf(CompositeByteBuf wrapped, ResourceLeakTracker<ByteBuf> leak) { SimpleLeakAwareCompositeByteBuf(CompositeByteBuf wrapped, ResourceLeakTracker<ByteBuf> leak) {
super(wrapped); super(wrapped);
this.leak = ObjectUtil.checkNotNull(leak, "leak"); this.leak = requireNonNull(leak, "leak");
} }
@Override @Override

View File

@ -15,6 +15,8 @@
*/ */
package io.netty.buffer; package io.netty.buffer;
import static java.util.Objects.requireNonNull;
import io.netty.util.ByteProcessor; import io.netty.util.ByteProcessor;
import java.io.IOException; import java.io.IOException;
@ -40,9 +42,7 @@ public class SwappedByteBuf extends ByteBuf {
private final ByteOrder order; private final ByteOrder order;
public SwappedByteBuf(ByteBuf buf) { public SwappedByteBuf(ByteBuf buf) {
if (buf == null) { requireNonNull(buf, "buf");
throw new NullPointerException("buf");
}
this.buf = buf; this.buf = buf;
if (buf.order() == ByteOrder.BIG_ENDIAN) { if (buf.order() == ByteOrder.BIG_ENDIAN) {
order = ByteOrder.LITTLE_ENDIAN; order = ByteOrder.LITTLE_ENDIAN;
@ -58,9 +58,7 @@ public class SwappedByteBuf extends ByteBuf {
@Override @Override
public ByteBuf order(ByteOrder endianness) { public ByteBuf order(ByteOrder endianness) {
if (endianness == null) { requireNonNull(endianness, "endianness");
throw new NullPointerException("endianness");
}
if (endianness == order) { if (endianness == order) {
return this; return this;
} }

View File

@ -15,6 +15,8 @@
*/ */
package io.netty.buffer; package io.netty.buffer;
import static java.util.Objects.requireNonNull;
import io.netty.buffer.CompositeByteBuf.ByteWrapper; import io.netty.buffer.CompositeByteBuf.ByteWrapper;
import io.netty.util.internal.PlatformDependent; import io.netty.util.internal.PlatformDependent;
@ -575,9 +577,7 @@ public final class Unpooled {
* {@code 0} and the length of the encoded string respectively. * {@code 0} and the length of the encoded string respectively.
*/ */
public static ByteBuf copiedBuffer(CharSequence string, Charset charset) { public static ByteBuf copiedBuffer(CharSequence string, Charset charset) {
if (string == null) { requireNonNull(string, "string");
throw new NullPointerException("string");
}
if (string instanceof CharBuffer) { if (string instanceof CharBuffer) {
return copiedBuffer((CharBuffer) string, charset); return copiedBuffer((CharBuffer) string, charset);
@ -594,9 +594,7 @@ public final class Unpooled {
*/ */
public static ByteBuf copiedBuffer( public static ByteBuf copiedBuffer(
CharSequence string, int offset, int length, Charset charset) { CharSequence string, int offset, int length, Charset charset) {
if (string == null) { requireNonNull(string, "string");
throw new NullPointerException("string");
}
if (length == 0) { if (length == 0) {
return EMPTY_BUFFER; return EMPTY_BUFFER;
} }
@ -626,9 +624,7 @@ public final class Unpooled {
* {@code 0} and the length of the encoded string respectively. * {@code 0} and the length of the encoded string respectively.
*/ */
public static ByteBuf copiedBuffer(char[] array, Charset charset) { public static ByteBuf copiedBuffer(char[] array, Charset charset) {
if (array == null) { requireNonNull(array, "array");
throw new NullPointerException("array");
}
return copiedBuffer(array, 0, array.length, charset); return copiedBuffer(array, 0, array.length, charset);
} }
@ -639,9 +635,7 @@ public final class Unpooled {
* {@code 0} and the length of the encoded string respectively. * {@code 0} and the length of the encoded string respectively.
*/ */
public static ByteBuf copiedBuffer(char[] array, int offset, int length, Charset charset) { public static ByteBuf copiedBuffer(char[] array, int offset, int length, Charset charset) {
if (array == null) { requireNonNull(array, "array");
throw new NullPointerException("array");
}
if (length == 0) { if (length == 0) {
return EMPTY_BUFFER; return EMPTY_BUFFER;
} }

View File

@ -16,6 +16,7 @@
package io.netty.buffer; package io.netty.buffer;
import static io.netty.util.internal.ObjectUtil.checkPositiveOrZero; import static io.netty.util.internal.ObjectUtil.checkPositiveOrZero;
import static java.util.Objects.requireNonNull;
import io.netty.util.internal.PlatformDependent; import io.netty.util.internal.PlatformDependent;
@ -51,9 +52,7 @@ public class UnpooledDirectByteBuf extends AbstractReferenceCountedByteBuf {
*/ */
public UnpooledDirectByteBuf(ByteBufAllocator alloc, int initialCapacity, int maxCapacity) { public UnpooledDirectByteBuf(ByteBufAllocator alloc, int initialCapacity, int maxCapacity) {
super(maxCapacity); super(maxCapacity);
if (alloc == null) { requireNonNull(alloc, "alloc");
throw new NullPointerException("alloc");
}
checkPositiveOrZero(initialCapacity, "initialCapacity"); checkPositiveOrZero(initialCapacity, "initialCapacity");
checkPositiveOrZero(maxCapacity, "maxCapacity"); checkPositiveOrZero(maxCapacity, "maxCapacity");
if (initialCapacity > maxCapacity) { if (initialCapacity > maxCapacity) {
@ -72,12 +71,8 @@ public class UnpooledDirectByteBuf extends AbstractReferenceCountedByteBuf {
*/ */
protected UnpooledDirectByteBuf(ByteBufAllocator alloc, ByteBuffer initialBuffer, int maxCapacity) { protected UnpooledDirectByteBuf(ByteBufAllocator alloc, ByteBuffer initialBuffer, int maxCapacity) {
super(maxCapacity); super(maxCapacity);
if (alloc == null) { requireNonNull(alloc, "alloc");
throw new NullPointerException("alloc"); requireNonNull(initialBuffer, "initialBuffer");
}
if (initialBuffer == null) {
throw new NullPointerException("initialBuffer");
}
if (!initialBuffer.isDirect()) { if (!initialBuffer.isDirect()) {
throw new IllegalArgumentException("initialBuffer is not a direct buffer."); throw new IllegalArgumentException("initialBuffer is not a direct buffer.");
} }

View File

@ -15,6 +15,8 @@
*/ */
package io.netty.buffer; package io.netty.buffer;
import static java.util.Objects.requireNonNull;
import io.netty.util.internal.EmptyArrays; import io.netty.util.internal.EmptyArrays;
import io.netty.util.internal.PlatformDependent; import io.netty.util.internal.PlatformDependent;
@ -28,8 +30,6 @@ import java.nio.channels.FileChannel;
import java.nio.channels.GatheringByteChannel; import java.nio.channels.GatheringByteChannel;
import java.nio.channels.ScatteringByteChannel; import java.nio.channels.ScatteringByteChannel;
import static io.netty.util.internal.ObjectUtil.checkNotNull;
/** /**
* Big endian Java heap buffer implementation. It is recommended to use * Big endian Java heap buffer implementation. It is recommended to use
* {@link UnpooledByteBufAllocator#heapBuffer(int, int)}, {@link Unpooled#buffer(int)} and * {@link UnpooledByteBufAllocator#heapBuffer(int, int)}, {@link Unpooled#buffer(int)} and
@ -50,7 +50,7 @@ public class UnpooledHeapByteBuf extends AbstractReferenceCountedByteBuf {
public UnpooledHeapByteBuf(ByteBufAllocator alloc, int initialCapacity, int maxCapacity) { public UnpooledHeapByteBuf(ByteBufAllocator alloc, int initialCapacity, int maxCapacity) {
super(maxCapacity); super(maxCapacity);
checkNotNull(alloc, "alloc"); requireNonNull(alloc, "alloc");
if (initialCapacity > maxCapacity) { if (initialCapacity > maxCapacity) {
throw new IllegalArgumentException(String.format( throw new IllegalArgumentException(String.format(
@ -71,8 +71,8 @@ public class UnpooledHeapByteBuf extends AbstractReferenceCountedByteBuf {
protected UnpooledHeapByteBuf(ByteBufAllocator alloc, byte[] initialArray, int maxCapacity) { protected UnpooledHeapByteBuf(ByteBufAllocator alloc, byte[] initialArray, int maxCapacity) {
super(maxCapacity); super(maxCapacity);
checkNotNull(alloc, "alloc"); requireNonNull(alloc, "alloc");
checkNotNull(initialArray, "initialArray"); requireNonNull(initialArray, "initialArray");
if (initialArray.length > maxCapacity) { if (initialArray.length > maxCapacity) {
throw new IllegalArgumentException(String.format( throw new IllegalArgumentException(String.format(

View File

@ -16,6 +16,7 @@
package io.netty.buffer; package io.netty.buffer;
import static io.netty.util.internal.ObjectUtil.checkPositiveOrZero; import static io.netty.util.internal.ObjectUtil.checkPositiveOrZero;
import static java.util.Objects.requireNonNull;
import io.netty.util.internal.PlatformDependent; import io.netty.util.internal.PlatformDependent;
@ -52,9 +53,7 @@ public class UnpooledUnsafeDirectByteBuf extends AbstractReferenceCountedByteBuf
*/ */
public UnpooledUnsafeDirectByteBuf(ByteBufAllocator alloc, int initialCapacity, int maxCapacity) { public UnpooledUnsafeDirectByteBuf(ByteBufAllocator alloc, int initialCapacity, int maxCapacity) {
super(maxCapacity); super(maxCapacity);
if (alloc == null) { requireNonNull(alloc, "alloc");
throw new NullPointerException("alloc");
}
checkPositiveOrZero(initialCapacity, "initialCapacity"); checkPositiveOrZero(initialCapacity, "initialCapacity");
checkPositiveOrZero(maxCapacity, "maxCapacity"); checkPositiveOrZero(maxCapacity, "maxCapacity");
if (initialCapacity > maxCapacity) { if (initialCapacity > maxCapacity) {
@ -86,12 +85,8 @@ public class UnpooledUnsafeDirectByteBuf extends AbstractReferenceCountedByteBuf
UnpooledUnsafeDirectByteBuf(ByteBufAllocator alloc, ByteBuffer initialBuffer, int maxCapacity, boolean doFree) { UnpooledUnsafeDirectByteBuf(ByteBufAllocator alloc, ByteBuffer initialBuffer, int maxCapacity, boolean doFree) {
super(maxCapacity); super(maxCapacity);
if (alloc == null) { requireNonNull(alloc, "alloc");
throw new NullPointerException("alloc"); requireNonNull(initialBuffer, "initialBuffer");
}
if (initialBuffer == null) {
throw new NullPointerException("initialBuffer");
}
if (!initialBuffer.isDirect()) { if (!initialBuffer.isDirect()) {
throw new IllegalArgumentException("initialBuffer is not a direct buffer."); throw new IllegalArgumentException("initialBuffer is not a direct buffer.");
} }

View File

@ -15,6 +15,8 @@
*/ */
package io.netty.buffer; package io.netty.buffer;
import static java.util.Objects.requireNonNull;
import java.nio.ByteOrder; import java.nio.ByteOrder;
/** /**
@ -31,9 +33,7 @@ final class UnreleasableByteBuf extends WrappedByteBuf {
@Override @Override
public ByteBuf order(ByteOrder endianness) { public ByteBuf order(ByteOrder endianness) {
if (endianness == null) { requireNonNull(endianness, "endianness");
throw new NullPointerException("endianness");
}
if (endianness == order()) { if (endianness == order()) {
return this; return this;
} }

View File

@ -25,8 +25,8 @@ import java.nio.ByteOrder;
import java.nio.ReadOnlyBufferException; import java.nio.ReadOnlyBufferException;
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.PlatformDependent.BIG_ENDIAN_NATIVE_ORDER; import static io.netty.util.internal.PlatformDependent.BIG_ENDIAN_NATIVE_ORDER;
import static java.util.Objects.requireNonNull;
/** /**
* All operations get and set as {@link ByteOrder#BIG_ENDIAN}. * All operations get and set as {@link ByteOrder#BIG_ENDIAN}.
@ -463,7 +463,7 @@ final class UnsafeByteBufUtil {
static void getBytes(AbstractByteBuf buf, long addr, int index, ByteBuf dst, int dstIndex, int length) { static void getBytes(AbstractByteBuf buf, long addr, int index, ByteBuf dst, int dstIndex, int length) {
buf.checkIndex(index, length); buf.checkIndex(index, length);
checkNotNull(dst, "dst"); requireNonNull(dst, "dst");
if (isOutOfBounds(dstIndex, length, dst.capacity())) { if (isOutOfBounds(dstIndex, length, dst.capacity())) {
throw new IndexOutOfBoundsException("dstIndex: " + dstIndex); throw new IndexOutOfBoundsException("dstIndex: " + dstIndex);
} }
@ -479,7 +479,7 @@ final class UnsafeByteBufUtil {
static void getBytes(AbstractByteBuf buf, long addr, int index, byte[] dst, int dstIndex, int length) { static void getBytes(AbstractByteBuf buf, long addr, int index, byte[] dst, int dstIndex, int length) {
buf.checkIndex(index, length); buf.checkIndex(index, length);
checkNotNull(dst, "dst"); requireNonNull(dst, "dst");
if (isOutOfBounds(dstIndex, length, dst.length)) { if (isOutOfBounds(dstIndex, length, dst.length)) {
throw new IndexOutOfBoundsException("dstIndex: " + dstIndex); throw new IndexOutOfBoundsException("dstIndex: " + dstIndex);
} }
@ -514,7 +514,7 @@ final class UnsafeByteBufUtil {
static void setBytes(AbstractByteBuf buf, long addr, int index, ByteBuf src, int srcIndex, int length) { static void setBytes(AbstractByteBuf buf, long addr, int index, ByteBuf src, int srcIndex, int length) {
buf.checkIndex(index, length); buf.checkIndex(index, length);
checkNotNull(src, "src"); requireNonNull(src, "src");
if (isOutOfBounds(srcIndex, length, src.capacity())) { if (isOutOfBounds(srcIndex, length, src.capacity())) {
throw new IndexOutOfBoundsException("srcIndex: " + srcIndex); throw new IndexOutOfBoundsException("srcIndex: " + srcIndex);
} }

View File

@ -16,6 +16,8 @@
package io.netty.buffer; package io.netty.buffer;
import static java.util.Objects.requireNonNull;
import io.netty.util.ByteProcessor; import io.netty.util.ByteProcessor;
import io.netty.util.internal.StringUtil; import io.netty.util.internal.StringUtil;
@ -41,9 +43,7 @@ class WrappedByteBuf extends ByteBuf {
protected final ByteBuf buf; protected final ByteBuf buf;
protected WrappedByteBuf(ByteBuf buf) { protected WrappedByteBuf(ByteBuf buf) {
if (buf == null) { requireNonNull(buf, "buf");
throw new NullPointerException("buf");
}
this.buf = buf; this.buf = buf;
} }

View File

@ -27,7 +27,7 @@ import io.netty.util.internal.UnstableApi;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import static io.netty.util.internal.ObjectUtil.checkNotNull; import static java.util.Objects.requireNonNull;
/** /**
* A skeletal implementation of {@link DnsMessage}. * A skeletal implementation of {@link DnsMessage}.
@ -87,7 +87,7 @@ public abstract class AbstractDnsMessage extends AbstractReferenceCounted implem
@Override @Override
public DnsMessage setOpCode(DnsOpCode opCode) { public DnsMessage setOpCode(DnsOpCode opCode) {
this.opCode = checkNotNull(opCode, "opCode"); this.opCode = requireNonNull(opCode, "opCode");
return this; return this;
} }
@ -452,11 +452,11 @@ public abstract class AbstractDnsMessage extends AbstractReferenceCounted implem
} }
private static int sectionOrdinal(DnsSection section) { private static int sectionOrdinal(DnsSection section) {
return checkNotNull(section, "section").ordinal(); return requireNonNull(section, "section").ordinal();
} }
private static DnsRecord checkQuestion(int section, DnsRecord record) { private static DnsRecord checkQuestion(int section, DnsRecord record) {
if (section == SECTION_QUESTION && !(checkNotNull(record, "record") instanceof DnsQuestion)) { if (section == SECTION_QUESTION && !(requireNonNull(record, "record") instanceof DnsQuestion)) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"record: " + record + " (expected: " + StringUtil.simpleClassName(DnsQuestion.class) + ')'); "record: " + record + " (expected: " + StringUtil.simpleClassName(DnsQuestion.class) + ')');
} }

View File

@ -20,7 +20,7 @@ import io.netty.util.internal.UnstableApi;
import java.net.IDN; import java.net.IDN;
import static io.netty.util.internal.ObjectUtil.checkNotNull; import static java.util.Objects.requireNonNull;
/** /**
* A skeletal implementation of {@link DnsRecord}. * A skeletal implementation of {@link DnsRecord}.
@ -69,8 +69,8 @@ public abstract class AbstractDnsRecord implements DnsRecord {
// See: // See:
// - https://github.com/netty/netty/issues/4937 // - https://github.com/netty/netty/issues/4937
// - https://github.com/netty/netty/issues/4935 // - https://github.com/netty/netty/issues/4935
this.name = appendTrailingDot(IDN.toASCII(checkNotNull(name, "name"))); this.name = appendTrailingDot(IDN.toASCII(requireNonNull(name, "name")));
this.type = checkNotNull(type, "type"); this.type = requireNonNull(type, "type");
this.dnsClass = (short) dnsClass; this.dnsClass = (short) dnsClass;
this.timeToLive = timeToLive; this.timeToLive = timeToLive;
} }

View File

@ -25,7 +25,7 @@ import io.netty.util.internal.UnstableApi;
import java.util.List; import java.util.List;
import static io.netty.util.internal.ObjectUtil.checkNotNull; import static java.util.Objects.requireNonNull;
/** /**
* Decodes a {@link DatagramPacket} into a {@link DatagramDnsQuery}. * Decodes a {@link DatagramPacket} into a {@link DatagramDnsQuery}.
@ -47,7 +47,7 @@ public class DatagramDnsQueryDecoder extends MessageToMessageDecoder<DatagramPac
* Creates a new decoder with the specified {@code recordDecoder}. * Creates a new decoder with the specified {@code recordDecoder}.
*/ */
public DatagramDnsQueryDecoder(DnsRecordDecoder recordDecoder) { public DatagramDnsQueryDecoder(DnsRecordDecoder recordDecoder) {
this.recordDecoder = checkNotNull(recordDecoder, "recordDecoder"); this.recordDecoder = requireNonNull(recordDecoder, "recordDecoder");
} }
@Override @Override

View File

@ -26,7 +26,7 @@ import io.netty.util.internal.UnstableApi;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.util.List; import java.util.List;
import static io.netty.util.internal.ObjectUtil.checkNotNull; import static java.util.Objects.requireNonNull;
/** /**
* Encodes a {@link DatagramDnsQuery} (or an {@link AddressedEnvelope} of {@link DnsQuery}} into a * Encodes a {@link DatagramDnsQuery} (or an {@link AddressedEnvelope} of {@link DnsQuery}} into a
@ -49,7 +49,7 @@ public class DatagramDnsQueryEncoder extends MessageToMessageEncoder<AddressedEn
* Creates a new encoder with the specified {@code recordEncoder}. * Creates a new encoder with the specified {@code recordEncoder}.
*/ */
public DatagramDnsQueryEncoder(DnsRecordEncoder recordEncoder) { public DatagramDnsQueryEncoder(DnsRecordEncoder recordEncoder) {
this.recordEncoder = checkNotNull(recordEncoder, "recordEncoder"); this.recordEncoder = requireNonNull(recordEncoder, "recordEncoder");
} }
@Override @Override

View File

@ -25,7 +25,7 @@ import io.netty.util.internal.UnstableApi;
import java.util.List; import java.util.List;
import static io.netty.util.internal.ObjectUtil.checkNotNull; import static java.util.Objects.requireNonNull;
/** /**
* Decodes a {@link DatagramPacket} into a {@link DatagramDnsResponse}. * Decodes a {@link DatagramPacket} into a {@link DatagramDnsResponse}.
@ -47,7 +47,7 @@ public class DatagramDnsResponseDecoder extends MessageToMessageDecoder<Datagram
* Creates a new decoder with the specified {@code recordDecoder}. * Creates a new decoder with the specified {@code recordDecoder}.
*/ */
public DatagramDnsResponseDecoder(DnsRecordDecoder recordDecoder) { public DatagramDnsResponseDecoder(DnsRecordDecoder recordDecoder) {
this.recordDecoder = checkNotNull(recordDecoder, "recordDecoder"); this.recordDecoder = requireNonNull(recordDecoder, "recordDecoder");
} }
@Override @Override

View File

@ -26,7 +26,7 @@ import io.netty.util.internal.UnstableApi;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.util.List; import java.util.List;
import static io.netty.util.internal.ObjectUtil.checkNotNull; import static java.util.Objects.requireNonNull;
/** /**
* Encodes a {@link DatagramDnsResponse} (or an {@link AddressedEnvelope} of {@link DnsResponse}} into a * Encodes a {@link DatagramDnsResponse} (or an {@link AddressedEnvelope} of {@link DnsResponse}} into a
@ -50,7 +50,7 @@ public class DatagramDnsResponseEncoder
* Creates a new encoder with the specified {@code recordEncoder}. * Creates a new encoder with the specified {@code recordEncoder}.
*/ */
public DatagramDnsResponseEncoder(DnsRecordEncoder recordEncoder) { public DatagramDnsResponseEncoder(DnsRecordEncoder recordEncoder) {
this.recordEncoder = checkNotNull(recordEncoder, "recordEncoder"); this.recordEncoder = requireNonNull(recordEncoder, "recordEncoder");
} }
@Override @Override

View File

@ -15,7 +15,7 @@
*/ */
package io.netty.handler.codec.dns; package io.netty.handler.codec.dns;
import static io.netty.util.internal.ObjectUtil.checkNotNull; import static java.util.Objects.requireNonNull;
import io.netty.util.internal.StringUtil; import io.netty.util.internal.StringUtil;
import io.netty.util.internal.UnstableApi; import io.netty.util.internal.UnstableApi;
@ -44,7 +44,7 @@ public class DefaultDnsPtrRecord extends AbstractDnsRecord implements DnsPtrReco
public DefaultDnsPtrRecord( public DefaultDnsPtrRecord(
String name, int dnsClass, long timeToLive, String hostname) { String name, int dnsClass, long timeToLive, String hostname) {
super(name, DnsRecordType.PTR, dnsClass, timeToLive); super(name, DnsRecordType.PTR, dnsClass, timeToLive);
this.hostname = checkNotNull(hostname, "hostname"); this.hostname = requireNonNull(hostname, "hostname");
} }
@Override @Override

View File

@ -19,7 +19,7 @@ import io.netty.buffer.ByteBuf;
import io.netty.util.internal.StringUtil; import io.netty.util.internal.StringUtil;
import io.netty.util.internal.UnstableApi; import io.netty.util.internal.UnstableApi;
import static io.netty.util.internal.ObjectUtil.checkNotNull; import static java.util.Objects.requireNonNull;
/** /**
* The default {@code DnsRawRecord} implementation. * The default {@code DnsRawRecord} implementation.
@ -59,7 +59,7 @@ public class DefaultDnsRawRecord extends AbstractDnsRecord implements DnsRawReco
public DefaultDnsRawRecord( public DefaultDnsRawRecord(
String name, DnsRecordType type, int dnsClass, long timeToLive, ByteBuf content) { String name, DnsRecordType type, int dnsClass, long timeToLive, ByteBuf content) {
super(name, type, dnsClass, timeToLive); super(name, type, dnsClass, timeToLive);
this.content = checkNotNull(content, "content"); this.content = requireNonNull(content, "content");
} }
@Override @Override

View File

@ -17,7 +17,7 @@ package io.netty.handler.codec.dns;
import io.netty.util.internal.UnstableApi; import io.netty.util.internal.UnstableApi;
import static io.netty.util.internal.ObjectUtil.checkNotNull; import static java.util.Objects.requireNonNull;
/** /**
* The default {@link DnsResponse} implementation. * The default {@link DnsResponse} implementation.
@ -102,7 +102,7 @@ public class DefaultDnsResponse extends AbstractDnsMessage implements DnsRespons
@Override @Override
public DnsResponse setCode(DnsResponseCode code) { public DnsResponse setCode(DnsResponseCode code) {
this.code = checkNotNull(code, "code"); this.code = requireNonNull(code, "code");
return this; return this;
} }

View File

@ -17,7 +17,7 @@ package io.netty.handler.codec.dns;
import io.netty.util.internal.UnstableApi; import io.netty.util.internal.UnstableApi;
import static io.netty.util.internal.ObjectUtil.checkNotNull; import static java.util.Objects.requireNonNull;
/** /**
* The DNS {@code OpCode} as defined in <a href="https://tools.ietf.org/html/rfc2929">RFC2929</a>. * The DNS {@code OpCode} as defined in <a href="https://tools.ietf.org/html/rfc2929">RFC2929</a>.
@ -80,7 +80,7 @@ public class DnsOpCode implements Comparable<DnsOpCode> {
public DnsOpCode(int byteValue, String name) { public DnsOpCode(int byteValue, String name) {
this.byteValue = (byte) byteValue; this.byteValue = (byte) byteValue;
this.name = checkNotNull(name, "name"); this.name = requireNonNull(name, "name");
} }
public byte byteValue() { public byte byteValue() {

View File

@ -17,7 +17,7 @@ package io.netty.handler.codec.dns;
import io.netty.util.internal.UnstableApi; import io.netty.util.internal.UnstableApi;
import static io.netty.util.internal.ObjectUtil.checkNotNull; import static java.util.Objects.requireNonNull;
/** /**
* The DNS {@code RCODE}, as defined in <a href="https://tools.ietf.org/html/rfc2929">RFC2929</a>. * The DNS {@code RCODE}, as defined in <a href="https://tools.ietf.org/html/rfc2929">RFC2929</a>.
@ -173,7 +173,7 @@ public class DnsResponseCode implements Comparable<DnsResponseCode> {
} }
this.code = code; this.code = code;
this.name = checkNotNull(name, "name"); this.name = requireNonNull(name, "name");
} }
/** /**

View File

@ -15,6 +15,8 @@
*/ */
package io.netty.handler.codec.haproxy; package io.netty.handler.codec.haproxy;
import static java.util.Objects.requireNonNull;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.handler.codec.haproxy.HAProxyProxiedProtocol.AddressFamily; import io.netty.handler.codec.haproxy.HAProxyProxiedProtocol.AddressFamily;
import io.netty.util.ByteProcessor; import io.netty.util.ByteProcessor;
@ -89,10 +91,7 @@ public final class HAProxyMessage {
HAProxyProtocolVersion protocolVersion, HAProxyCommand command, HAProxyProxiedProtocol proxiedProtocol, HAProxyProtocolVersion protocolVersion, HAProxyCommand command, HAProxyProxiedProtocol proxiedProtocol,
String sourceAddress, String destinationAddress, int sourcePort, int destinationPort, String sourceAddress, String destinationAddress, int sourcePort, int destinationPort,
List<HAProxyTLV> tlvs) { List<HAProxyTLV> tlvs) {
requireNonNull(proxiedProtocol, "proxiedProtocol");
if (proxiedProtocol == null) {
throw new NullPointerException("proxiedProtocol");
}
AddressFamily addrFamily = proxiedProtocol.addressFamily(); AddressFamily addrFamily = proxiedProtocol.addressFamily();
checkAddress(sourceAddress, addrFamily); checkAddress(sourceAddress, addrFamily);
@ -118,9 +117,7 @@ public final class HAProxyMessage {
* @throws HAProxyProtocolException if any portion of the header is invalid * @throws HAProxyProtocolException if any portion of the header is invalid
*/ */
static HAProxyMessage decodeHeader(ByteBuf header) { static HAProxyMessage decodeHeader(ByteBuf header) {
if (header == null) { requireNonNull(header, "header");
throw new NullPointerException("header");
}
if (header.readableBytes() < 16) { if (header.readableBytes() < 16) {
throw new HAProxyProtocolException( throw new HAProxyProtocolException(
@ -416,9 +413,7 @@ public final class HAProxyMessage {
* @throws HAProxyProtocolException if the address is invalid * @throws HAProxyProtocolException if the address is invalid
*/ */
private static void checkAddress(String address, AddressFamily addrFamily) { private static void checkAddress(String address, AddressFamily addrFamily) {
if (addrFamily == null) { requireNonNull(addrFamily, "addrFamily");
throw new NullPointerException("addrFamily");
}
switch (addrFamily) { switch (addrFamily) {
case AF_UNSPEC: case AF_UNSPEC:
@ -430,9 +425,7 @@ public final class HAProxyMessage {
return; return;
} }
if (address == null) { requireNonNull(address, "address");
throw new NullPointerException("address");
}
switch (addrFamily) { switch (addrFamily) {
case AF_IPv4: case AF_IPv4:

View File

@ -19,7 +19,7 @@ package io.netty.handler.codec.haproxy;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.DefaultByteBufHolder; import io.netty.buffer.DefaultByteBufHolder;
import static io.netty.util.internal.ObjectUtil.*; import static java.util.Objects.requireNonNull;
/** /**
* A Type-Length Value (TLV vector) that can be added to the PROXY protocol * A Type-Length Value (TLV vector) that can be added to the PROXY protocol
@ -85,7 +85,7 @@ public class HAProxyTLV extends DefaultByteBufHolder {
*/ */
HAProxyTLV(final Type type, final byte typeByteValue, final ByteBuf content) { HAProxyTLV(final Type type, final byte typeByteValue, final ByteBuf content) {
super(content); super(content);
checkNotNull(type, "type"); requireNonNull(type, "type");
this.type = type; this.type = type;
this.typeByteValue = typeByteValue; this.typeByteValue = typeByteValue;

View File

@ -18,7 +18,7 @@ package io.netty.handler.codec.http;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import io.netty.util.IllegalReferenceCountException; import io.netty.util.IllegalReferenceCountException;
import static io.netty.util.internal.ObjectUtil.checkNotNull; import static java.util.Objects.requireNonNull;
/** /**
* Default implementation of {@link FullHttpRequest}. * Default implementation of {@link FullHttpRequest}.
@ -47,15 +47,15 @@ public class DefaultFullHttpRequest extends DefaultHttpRequest implements FullHt
public DefaultFullHttpRequest(HttpVersion httpVersion, HttpMethod method, String uri, public DefaultFullHttpRequest(HttpVersion httpVersion, HttpMethod method, String uri,
ByteBuf content, boolean validateHeaders) { ByteBuf content, boolean validateHeaders) {
super(httpVersion, method, uri, validateHeaders); super(httpVersion, method, uri, validateHeaders);
this.content = checkNotNull(content, "content"); this.content = requireNonNull(content, "content");
trailingHeader = new DefaultHttpHeaders(validateHeaders); trailingHeader = new DefaultHttpHeaders(validateHeaders);
} }
public DefaultFullHttpRequest(HttpVersion httpVersion, HttpMethod method, String uri, public DefaultFullHttpRequest(HttpVersion httpVersion, HttpMethod method, String uri,
ByteBuf content, HttpHeaders headers, HttpHeaders trailingHeader) { ByteBuf content, HttpHeaders headers, HttpHeaders trailingHeader) {
super(httpVersion, method, uri, headers); super(httpVersion, method, uri, headers);
this.content = checkNotNull(content, "content"); this.content = requireNonNull(content, "content");
this.trailingHeader = checkNotNull(trailingHeader, "trailingHeader"); this.trailingHeader = requireNonNull(trailingHeader, "trailingHeader");
} }
@Override @Override

View File

@ -19,7 +19,7 @@ import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import io.netty.util.IllegalReferenceCountException; import io.netty.util.IllegalReferenceCountException;
import static io.netty.util.internal.ObjectUtil.checkNotNull; import static java.util.Objects.requireNonNull;
/** /**
* Default implementation of a {@link FullHttpResponse}. * Default implementation of a {@link FullHttpResponse}.
@ -59,7 +59,7 @@ public class DefaultFullHttpResponse extends DefaultHttpResponse implements Full
public DefaultFullHttpResponse(HttpVersion version, HttpResponseStatus status, public DefaultFullHttpResponse(HttpVersion version, HttpResponseStatus status,
ByteBuf content, boolean validateHeaders, boolean singleFieldHeaders) { ByteBuf content, boolean validateHeaders, boolean singleFieldHeaders) {
super(version, status, validateHeaders, singleFieldHeaders); super(version, status, validateHeaders, singleFieldHeaders);
this.content = checkNotNull(content, "content"); this.content = requireNonNull(content, "content");
this.trailingHeaders = singleFieldHeaders ? new CombinedHttpHeaders(validateHeaders) this.trailingHeaders = singleFieldHeaders ? new CombinedHttpHeaders(validateHeaders)
: new DefaultHttpHeaders(validateHeaders); : new DefaultHttpHeaders(validateHeaders);
} }
@ -67,8 +67,8 @@ public class DefaultFullHttpResponse extends DefaultHttpResponse implements Full
public DefaultFullHttpResponse(HttpVersion version, HttpResponseStatus status, public DefaultFullHttpResponse(HttpVersion version, HttpResponseStatus status,
ByteBuf content, HttpHeaders headers, HttpHeaders trailingHeaders) { ByteBuf content, HttpHeaders headers, HttpHeaders trailingHeaders) {
super(version, status, headers); super(version, status, headers);
this.content = checkNotNull(content, "content"); this.content = requireNonNull(content, "content");
this.trailingHeaders = checkNotNull(trailingHeaders, "trailingHeaders"); this.trailingHeaders = requireNonNull(trailingHeaders, "trailingHeaders");
} }
@Override @Override

View File

@ -15,6 +15,8 @@
*/ */
package io.netty.handler.codec.http; package io.netty.handler.codec.http;
import static java.util.Objects.requireNonNull;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.util.internal.StringUtil; import io.netty.util.internal.StringUtil;
@ -29,9 +31,7 @@ public class DefaultHttpContent extends DefaultHttpObject implements HttpContent
* Creates a new instance with the specified chunk content. * Creates a new instance with the specified chunk content.
*/ */
public DefaultHttpContent(ByteBuf content) { public DefaultHttpContent(ByteBuf content) {
if (content == null) { requireNonNull(content, "content");
throw new NullPointerException("content");
}
this.content = content; this.content = content;
} }

View File

@ -15,7 +15,7 @@
*/ */
package io.netty.handler.codec.http; package io.netty.handler.codec.http;
import static io.netty.util.internal.ObjectUtil.checkNotNull; import static java.util.Objects.requireNonNull;
/** /**
* The default {@link HttpMessage} implementation. * The default {@link HttpMessage} implementation.
@ -45,8 +45,8 @@ public abstract class DefaultHttpMessage extends DefaultHttpObject implements Ht
* Creates a new instance. * Creates a new instance.
*/ */
protected DefaultHttpMessage(final HttpVersion version, HttpHeaders headers) { protected DefaultHttpMessage(final HttpVersion version, HttpHeaders headers) {
this.version = checkNotNull(version, "version"); this.version = requireNonNull(version, "version");
this.headers = checkNotNull(headers, "headers"); this.headers = requireNonNull(headers, "headers");
} }
@Override @Override
@ -89,9 +89,7 @@ public abstract class DefaultHttpMessage extends DefaultHttpObject implements Ht
@Override @Override
public HttpMessage setProtocolVersion(HttpVersion version) { public HttpMessage setProtocolVersion(HttpVersion version) {
if (version == null) { requireNonNull(version, "version");
throw new NullPointerException("version");
}
this.version = version; this.version = version;
return this; return this;
} }

View File

@ -15,6 +15,8 @@
*/ */
package io.netty.handler.codec.http; package io.netty.handler.codec.http;
import static java.util.Objects.requireNonNull;
import io.netty.handler.codec.DecoderResult; import io.netty.handler.codec.DecoderResult;
public class DefaultHttpObject implements HttpObject { public class DefaultHttpObject implements HttpObject {
@ -39,9 +41,7 @@ public class DefaultHttpObject implements HttpObject {
@Override @Override
public void setDecoderResult(DecoderResult decoderResult) { public void setDecoderResult(DecoderResult decoderResult) {
if (decoderResult == null) { requireNonNull(decoderResult, "decoderResult");
throw new NullPointerException("decoderResult");
}
this.decoderResult = decoderResult; this.decoderResult = decoderResult;
} }

View File

@ -15,7 +15,7 @@
*/ */
package io.netty.handler.codec.http; package io.netty.handler.codec.http;
import static io.netty.util.internal.ObjectUtil.checkNotNull; import static java.util.Objects.requireNonNull;
/** /**
* The default {@link HttpRequest} implementation. * The default {@link HttpRequest} implementation.
@ -46,8 +46,8 @@ public class DefaultHttpRequest extends DefaultHttpMessage implements HttpReques
*/ */
public DefaultHttpRequest(HttpVersion httpVersion, HttpMethod method, String uri, boolean validateHeaders) { public DefaultHttpRequest(HttpVersion httpVersion, HttpMethod method, String uri, boolean validateHeaders) {
super(httpVersion, validateHeaders, false); super(httpVersion, validateHeaders, false);
this.method = checkNotNull(method, "method"); this.method = requireNonNull(method, "method");
this.uri = checkNotNull(uri, "uri"); this.uri = requireNonNull(uri, "uri");
} }
/** /**
@ -60,8 +60,8 @@ public class DefaultHttpRequest extends DefaultHttpMessage implements HttpReques
*/ */
public DefaultHttpRequest(HttpVersion httpVersion, HttpMethod method, String uri, HttpHeaders headers) { public DefaultHttpRequest(HttpVersion httpVersion, HttpMethod method, String uri, HttpHeaders headers) {
super(httpVersion, headers); super(httpVersion, headers);
this.method = checkNotNull(method, "method"); this.method = requireNonNull(method, "method");
this.uri = checkNotNull(uri, "uri"); this.uri = requireNonNull(uri, "uri");
} }
@Override @Override
@ -88,18 +88,14 @@ public class DefaultHttpRequest extends DefaultHttpMessage implements HttpReques
@Override @Override
public HttpRequest setMethod(HttpMethod method) { public HttpRequest setMethod(HttpMethod method) {
if (method == null) { requireNonNull(method, "method");
throw new NullPointerException("method");
}
this.method = method; this.method = method;
return this; return this;
} }
@Override @Override
public HttpRequest setUri(String uri) { public HttpRequest setUri(String uri) {
if (uri == null) { requireNonNull(uri, "uri");
throw new NullPointerException("uri");
}
this.uri = uri; this.uri = uri;
return this; return this;
} }

View File

@ -15,7 +15,7 @@
*/ */
package io.netty.handler.codec.http; package io.netty.handler.codec.http;
import static io.netty.util.internal.ObjectUtil.checkNotNull; import static java.util.Objects.requireNonNull;
/** /**
* The default {@link HttpResponse} implementation. * The default {@link HttpResponse} implementation.
@ -60,7 +60,7 @@ public class DefaultHttpResponse extends DefaultHttpMessage implements HttpRespo
public DefaultHttpResponse(HttpVersion version, HttpResponseStatus status, boolean validateHeaders, public DefaultHttpResponse(HttpVersion version, HttpResponseStatus status, boolean validateHeaders,
boolean singleFieldHeaders) { boolean singleFieldHeaders) {
super(version, validateHeaders, singleFieldHeaders); super(version, validateHeaders, singleFieldHeaders);
this.status = checkNotNull(status, "status"); this.status = requireNonNull(status, "status");
} }
/** /**
@ -72,7 +72,7 @@ public class DefaultHttpResponse extends DefaultHttpMessage implements HttpRespo
*/ */
public DefaultHttpResponse(HttpVersion version, HttpResponseStatus status, HttpHeaders headers) { public DefaultHttpResponse(HttpVersion version, HttpResponseStatus status, HttpHeaders headers) {
super(version, headers); super(version, headers);
this.status = checkNotNull(status, "status"); this.status = requireNonNull(status, "status");
} }
@Override @Override
@ -88,9 +88,7 @@ public class DefaultHttpResponse extends DefaultHttpMessage implements HttpRespo
@Override @Override
public HttpResponse setStatus(HttpResponseStatus status) { public HttpResponse setStatus(HttpResponseStatus status) {
if (status == null) { requireNonNull(status, "status");
throw new NullPointerException("status");
}
this.status = status; this.status = status;
return this; return this;
} }

View File

@ -27,6 +27,7 @@ import java.util.Set;
import static io.netty.handler.codec.http.HttpResponseStatus.SWITCHING_PROTOCOLS; import static io.netty.handler.codec.http.HttpResponseStatus.SWITCHING_PROTOCOLS;
import static io.netty.util.ReferenceCountUtil.release; import static io.netty.util.ReferenceCountUtil.release;
import static java.util.Objects.requireNonNull;
/** /**
* Client-side handler for handling an HTTP upgrade handshake to another protocol. When the first * Client-side handler for handling an HTTP upgrade handshake to another protocol. When the first
@ -115,12 +116,8 @@ public class HttpClientUpgradeHandler extends HttpObjectAggregator implements Ch
public HttpClientUpgradeHandler(SourceCodec sourceCodec, UpgradeCodec upgradeCodec, public HttpClientUpgradeHandler(SourceCodec sourceCodec, UpgradeCodec upgradeCodec,
int maxContentLength) { int maxContentLength) {
super(maxContentLength); super(maxContentLength);
if (sourceCodec == null) { requireNonNull(sourceCodec, "sourceCodec");
throw new NullPointerException("sourceCodec"); requireNonNull(upgradeCodec, "upgradeCodec");
}
if (upgradeCodec == null) {
throw new NullPointerException("upgradeCodec");
}
this.sourceCodec = sourceCodec; this.sourceCodec = sourceCodec;
this.upgradeCodec = upgradeCodec; this.upgradeCodec = upgradeCodec;
} }

View File

@ -15,6 +15,8 @@
*/ */
package io.netty.handler.codec.http; package io.netty.handler.codec.http;
import static java.util.Objects.requireNonNull;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufHolder; import io.netty.buffer.ByteBufHolder;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
@ -350,12 +352,8 @@ public abstract class HttpContentEncoder extends MessageToMessageCodec<HttpReque
private final EmbeddedChannel contentEncoder; private final EmbeddedChannel contentEncoder;
public Result(String targetContentEncoding, EmbeddedChannel contentEncoder) { public Result(String targetContentEncoding, EmbeddedChannel contentEncoder) {
if (targetContentEncoding == null) { requireNonNull(targetContentEncoding, "targetContentEncoding");
throw new NullPointerException("targetContentEncoding"); requireNonNull(contentEncoder, "contentEncoder");
}
if (contentEncoder == null) {
throw new NullPointerException("contentEncoder");
}
this.targetContentEncoding = targetContentEncoding; this.targetContentEncoding = targetContentEncoding;
this.contentEncoder = contentEncoder; this.contentEncoder = contentEncoder;

View File

@ -35,7 +35,7 @@ import java.util.Set;
import static io.netty.util.AsciiString.contentEquals; import static io.netty.util.AsciiString.contentEquals;
import static io.netty.util.AsciiString.contentEqualsIgnoreCase; import static io.netty.util.AsciiString.contentEqualsIgnoreCase;
import static io.netty.util.AsciiString.trim; import static io.netty.util.AsciiString.trim;
import static io.netty.util.internal.ObjectUtil.checkNotNull; import static java.util.Objects.requireNonNull;
/** /**
* Provides the constants for the standard HTTP header names and values and * Provides the constants for the standard HTTP header names and values and
@ -950,9 +950,7 @@ public abstract class HttpHeaders implements Iterable<Map.Entry<String, String>>
* @return {@code this} * @return {@code this}
*/ */
public HttpHeaders add(HttpHeaders headers) { public HttpHeaders add(HttpHeaders headers) {
if (headers == null) { requireNonNull(headers, "headers");
throw new NullPointerException("headers");
}
for (Map.Entry<String, String> e: headers) { for (Map.Entry<String, String> e: headers) {
add(e.getKey(), e.getValue()); add(e.getKey(), e.getValue());
} }
@ -1031,7 +1029,7 @@ public abstract class HttpHeaders implements Iterable<Map.Entry<String, String>>
* @return {@code this} * @return {@code this}
*/ */
public HttpHeaders set(HttpHeaders headers) { public HttpHeaders set(HttpHeaders headers) {
checkNotNull(headers, "headers"); requireNonNull(headers, "headers");
clear(); clear();
@ -1052,7 +1050,7 @@ public abstract class HttpHeaders implements Iterable<Map.Entry<String, String>>
* @return {@code this} * @return {@code this}
*/ */
public HttpHeaders setAll(HttpHeaders headers) { public HttpHeaders setAll(HttpHeaders headers) {
checkNotNull(headers, "headers"); requireNonNull(headers, "headers");
if (headers.isEmpty()) { if (headers.isEmpty()) {
return this; return this;

View File

@ -18,7 +18,7 @@ package io.netty.handler.codec.http;
import io.netty.util.AsciiString; import io.netty.util.AsciiString;
import static io.netty.util.internal.MathUtil.findNextPositivePowerOfTwo; import static io.netty.util.internal.MathUtil.findNextPositivePowerOfTwo;
import static io.netty.util.internal.ObjectUtil.checkNotNull; import static java.util.Objects.requireNonNull;
/** /**
* The request method of HTTP or its derived protocols, such as * The request method of HTTP or its derived protocols, such as
@ -120,7 +120,7 @@ public class HttpMethod implements Comparable<HttpMethod> {
* <a href="http://en.wikipedia.org/wiki/Internet_Content_Adaptation_Protocol">ICAP</a> * <a href="http://en.wikipedia.org/wiki/Internet_Content_Adaptation_Protocol">ICAP</a>
*/ */
public HttpMethod(String name) { public HttpMethod(String name) {
name = checkNotNull(name, "name").trim(); name = requireNonNull(name, "name").trim();
if (name.isEmpty()) { if (name.isEmpty()) {
throw new IllegalArgumentException("empty name"); throw new IllegalArgumentException("empty name");
} }

View File

@ -23,6 +23,7 @@ import io.netty.util.CharsetUtil;
import static io.netty.handler.codec.http.HttpConstants.SP; import static io.netty.handler.codec.http.HttpConstants.SP;
import static io.netty.util.ByteProcessor.FIND_ASCII_SPACE; import static io.netty.util.ByteProcessor.FIND_ASCII_SPACE;
import static java.lang.Integer.parseInt; import static java.lang.Integer.parseInt;
import static java.util.Objects.requireNonNull;
/** /**
* The response code and its description of HTTP or its derived protocols, such as * The response code and its description of HTTP or its derived protocols, such as
@ -543,9 +544,7 @@ public class HttpResponseStatus implements Comparable<HttpResponseStatus> {
"code: " + code + " (expected: 0+)"); "code: " + code + " (expected: 0+)");
} }
if (reasonPhrase == null) { requireNonNull(reasonPhrase, "reasonPhrase");
throw new NullPointerException("reasonPhrase");
}
for (int i = 0; i < reasonPhrase.length(); i ++) { for (int i = 0; i < reasonPhrase.length(); i ++) {
char c = reasonPhrase.charAt(i); char c = reasonPhrase.charAt(i);

View File

@ -30,7 +30,7 @@ import java.util.List;
import static io.netty.handler.codec.http.HttpResponseStatus.SWITCHING_PROTOCOLS; import static io.netty.handler.codec.http.HttpResponseStatus.SWITCHING_PROTOCOLS;
import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1; import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1;
import static io.netty.util.internal.ObjectUtil.checkNotNull; import static java.util.Objects.requireNonNull;
/** /**
* A server-side handler that receives HTTP requests and optionally performs a protocol switch if * A server-side handler that receives HTTP requests and optionally performs a protocol switch if
@ -201,8 +201,8 @@ public class HttpServerUpgradeHandler extends HttpObjectAggregator {
SourceCodec sourceCodec, UpgradeCodecFactory upgradeCodecFactory, int maxContentLength) { SourceCodec sourceCodec, UpgradeCodecFactory upgradeCodecFactory, int maxContentLength) {
super(maxContentLength); super(maxContentLength);
this.sourceCodec = checkNotNull(sourceCodec, "sourceCodec"); this.sourceCodec = requireNonNull(sourceCodec, "sourceCodec");
this.upgradeCodecFactory = checkNotNull(upgradeCodecFactory, "upgradeCodecFactory"); this.upgradeCodecFactory = requireNonNull(upgradeCodecFactory, "upgradeCodecFactory");
} }
@Override @Override

View File

@ -15,6 +15,8 @@
*/ */
package io.netty.handler.codec.http; package io.netty.handler.codec.http;
import static java.util.Objects.requireNonNull;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.URI; import java.net.URI;
import java.nio.charset.Charset; import java.nio.charset.Charset;
@ -455,9 +457,7 @@ public final class HttpUtil {
* @throws NullPointerException in case if {@code contentTypeValue == null} * @throws NullPointerException in case if {@code contentTypeValue == null}
*/ */
public static CharSequence getCharsetAsSequence(CharSequence contentTypeValue) { public static CharSequence getCharsetAsSequence(CharSequence contentTypeValue) {
if (contentTypeValue == null) { requireNonNull(contentTypeValue, "contentTypeValue");
throw new NullPointerException("contentTypeValue");
}
int indexOfCharset = AsciiString.indexOfIgnoreCaseAscii(contentTypeValue, CHARSET_EQUALS, 0); int indexOfCharset = AsciiString.indexOfIgnoreCaseAscii(contentTypeValue, CHARSET_EQUALS, 0);
if (indexOfCharset == AsciiString.INDEX_NOT_FOUND) { if (indexOfCharset == AsciiString.INDEX_NOT_FOUND) {
@ -511,9 +511,7 @@ public final class HttpUtil {
* @throws NullPointerException in case if {@code contentTypeValue == null} * @throws NullPointerException in case if {@code contentTypeValue == null}
*/ */
public static CharSequence getMimeType(CharSequence contentTypeValue) { public static CharSequence getMimeType(CharSequence contentTypeValue) {
if (contentTypeValue == null) { requireNonNull(contentTypeValue, "contentTypeValue");
throw new NullPointerException("contentTypeValue");
}
int indexOfSemicolon = AsciiString.indexOfIgnoreCaseAscii(contentTypeValue, SEMICOLON, 0); int indexOfSemicolon = AsciiString.indexOfIgnoreCaseAscii(contentTypeValue, SEMICOLON, 0);
if (indexOfSemicolon != AsciiString.INDEX_NOT_FOUND) { if (indexOfSemicolon != AsciiString.INDEX_NOT_FOUND) {

View File

@ -15,6 +15,8 @@
*/ */
package io.netty.handler.codec.http; package io.netty.handler.codec.http;
import static java.util.Objects.requireNonNull;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.util.CharsetUtil; import io.netty.util.CharsetUtil;
@ -53,9 +55,7 @@ public class HttpVersion implements Comparable<HttpVersion> {
* returned. * returned.
*/ */
public static HttpVersion valueOf(String text) { public static HttpVersion valueOf(String text) {
if (text == null) { requireNonNull(text, "text");
throw new NullPointerException("text");
}
text = text.trim(); text = text.trim();
@ -107,9 +107,7 @@ public class HttpVersion implements Comparable<HttpVersion> {
* the {@code "Connection"} header is set to {@code "close"} explicitly. * the {@code "Connection"} header is set to {@code "close"} explicitly.
*/ */
public HttpVersion(String text, boolean keepAliveDefault) { public HttpVersion(String text, boolean keepAliveDefault) {
if (text == null) { requireNonNull(text, "text");
throw new NullPointerException("text");
}
text = text.trim().toUpperCase(); text = text.trim().toUpperCase();
if (text.isEmpty()) { if (text.isEmpty()) {
@ -149,9 +147,7 @@ public class HttpVersion implements Comparable<HttpVersion> {
private HttpVersion( private HttpVersion(
String protocolName, int majorVersion, int minorVersion, String protocolName, int majorVersion, int minorVersion,
boolean keepAliveDefault, boolean bytes) { boolean keepAliveDefault, boolean bytes) {
if (protocolName == null) { requireNonNull(protocolName, "protocolName");
throw new NullPointerException("protocolName");
}
protocolName = protocolName.trim().toUpperCase(); protocolName = protocolName.trim().toUpperCase();
if (protocolName.isEmpty()) { if (protocolName.isEmpty()) {

View File

@ -31,8 +31,9 @@ import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import static io.netty.util.internal.ObjectUtil.*; import static io.netty.util.internal.ObjectUtil.checkPositive;
import static io.netty.util.internal.StringUtil.*; import static io.netty.util.internal.StringUtil.*;
import static java.util.Objects.requireNonNull;
/** /**
* Splits an HTTP query string into a path string and key-value parameter pairs. * Splits an HTTP query string into a path string and key-value parameter pairs.
@ -109,8 +110,8 @@ public class QueryStringDecoder {
* specified charset. * specified charset.
*/ */
public QueryStringDecoder(String uri, Charset charset, boolean hasPath, int maxParams) { public QueryStringDecoder(String uri, Charset charset, boolean hasPath, int maxParams) {
this.uri = checkNotNull(uri, "uri"); this.uri = requireNonNull(uri, "uri");
this.charset = checkNotNull(charset, "charset"); this.charset = requireNonNull(charset, "charset");
this.maxParams = checkPositive(maxParams, "maxParams"); this.maxParams = checkPositive(maxParams, "maxParams");
// `-1` means that path end index will be initialized lazily // `-1` means that path end index will be initialized lazily
@ -145,7 +146,7 @@ public class QueryStringDecoder {
String rawQuery = uri.getRawQuery(); String rawQuery = uri.getRawQuery();
// Also take care of cut of things like "http://localhost" // Also take care of cut of things like "http://localhost"
this.uri = rawQuery == null? rawPath : rawPath + '?' + rawQuery; this.uri = rawQuery == null? rawPath : rawPath + '?' + rawQuery;
this.charset = checkNotNull(charset, "charset"); this.charset = requireNonNull(charset, "charset");
this.maxParams = checkPositive(maxParams, "maxParams"); this.maxParams = checkPositive(maxParams, "maxParams");
pathEndIdx = rawPath.length(); pathEndIdx = rawPath.length();
} }

View File

@ -15,7 +15,7 @@
*/ */
package io.netty.handler.codec.http; package io.netty.handler.codec.http;
import io.netty.util.internal.ObjectUtil; import static java.util.Objects.requireNonNull;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.URI; import java.net.URI;
@ -62,7 +62,7 @@ public class QueryStringEncoder {
* Adds a parameter with the specified name and value to this encoder. * Adds a parameter with the specified name and value to this encoder.
*/ */
public void addParam(String name, String value) { public void addParam(String name, String value) {
ObjectUtil.checkNotNull(name, "name"); requireNonNull(name, "name");
if (hasParams) { if (hasParams) {
uriBuilder.append('&'); uriBuilder.append('&');
} else { } else {

View File

@ -19,7 +19,7 @@ import io.netty.handler.codec.DateFormatter;
import java.util.Date; import java.util.Date;
import static io.netty.util.internal.ObjectUtil.checkNotNull; import static java.util.Objects.requireNonNull;
/** /**
* A <a href="http://tools.ietf.org/html/rfc6265">RFC6265</a> compliant cookie decoder to be used client side. * A <a href="http://tools.ietf.org/html/rfc6265">RFC6265</a> compliant cookie decoder to be used client side.
@ -52,7 +52,7 @@ public final class ClientCookieDecoder extends CookieDecoder {
* @return the decoded {@link Cookie} * @return the decoded {@link Cookie}
*/ */
public Cookie decode(String header) { public Cookie decode(String header) {
final int headerLen = checkNotNull(header, "header").length(); final int headerLen = requireNonNull(header, "header").length();
if (headerLen == 0) { if (headerLen == 0) {
return null; return null;

View File

@ -20,7 +20,8 @@ import static io.netty.handler.codec.http.cookie.CookieUtil.addQuoted;
import static io.netty.handler.codec.http.cookie.CookieUtil.stringBuilder; import static io.netty.handler.codec.http.cookie.CookieUtil.stringBuilder;
import static io.netty.handler.codec.http.cookie.CookieUtil.stripTrailingSeparator; import static io.netty.handler.codec.http.cookie.CookieUtil.stripTrailingSeparator;
import static io.netty.handler.codec.http.cookie.CookieUtil.stripTrailingSeparatorOrNull; import static io.netty.handler.codec.http.cookie.CookieUtil.stripTrailingSeparatorOrNull;
import static io.netty.util.internal.ObjectUtil.checkNotNull; import static java.util.Objects.requireNonNull;
import io.netty.handler.codec.http.HttpRequest; import io.netty.handler.codec.http.HttpRequest;
import io.netty.util.internal.InternalThreadLocalMap; import io.netty.util.internal.InternalThreadLocalMap;
@ -83,7 +84,7 @@ public final class ClientCookieEncoder extends CookieEncoder {
*/ */
public String encode(Cookie cookie) { public String encode(Cookie cookie) {
StringBuilder buf = stringBuilder(); StringBuilder buf = stringBuilder();
encode(buf, checkNotNull(cookie, "cookie")); encode(buf, requireNonNull(cookie, "cookie"));
return stripTrailingSeparator(buf); return stripTrailingSeparator(buf);
} }
@ -118,7 +119,7 @@ public final class ClientCookieEncoder extends CookieEncoder {
* @return a Rfc6265 style Cookie header value, null if no cookies are passed. * @return a Rfc6265 style Cookie header value, null if no cookies are passed.
*/ */
public String encode(Cookie... cookies) { public String encode(Cookie... cookies) {
if (checkNotNull(cookies, "cookies").length == 0) { if (requireNonNull(cookies, "cookies").length == 0) {
return null; return null;
} }
@ -149,7 +150,7 @@ public final class ClientCookieEncoder extends CookieEncoder {
* @return a Rfc6265 style Cookie header value, null if no cookies are passed. * @return a Rfc6265 style Cookie header value, null if no cookies are passed.
*/ */
public String encode(Collection<? extends Cookie> cookies) { public String encode(Collection<? extends Cookie> cookies) {
if (checkNotNull(cookies, "cookies").isEmpty()) { if (requireNonNull(cookies, "cookies").isEmpty()) {
return null; return null;
} }
@ -179,7 +180,7 @@ public final class ClientCookieEncoder extends CookieEncoder {
* @return a Rfc6265 style Cookie header value, null if no cookies are passed. * @return a Rfc6265 style Cookie header value, null if no cookies are passed.
*/ */
public String encode(Iterable<? extends Cookie> cookies) { public String encode(Iterable<? extends Cookie> cookies) {
Iterator<? extends Cookie> cookiesIt = checkNotNull(cookies, "cookies").iterator(); Iterator<? extends Cookie> cookiesIt = requireNonNull(cookies, "cookies").iterator();
if (!cookiesIt.hasNext()) { if (!cookiesIt.hasNext()) {
return null; return null;
} }

View File

@ -16,7 +16,7 @@
package io.netty.handler.codec.http.cookie; package io.netty.handler.codec.http.cookie;
import static io.netty.handler.codec.http.cookie.CookieUtil.*; import static io.netty.handler.codec.http.cookie.CookieUtil.*;
import static io.netty.util.internal.ObjectUtil.checkNotNull; import static java.util.Objects.requireNonNull;
/** /**
* The default {@link Cookie} implementation. * The default {@link Cookie} implementation.
@ -36,7 +36,7 @@ public class DefaultCookie implements Cookie {
* Creates a new cookie with the specified name and value. * Creates a new cookie with the specified name and value.
*/ */
public DefaultCookie(String name, String value) { public DefaultCookie(String name, String value) {
name = checkNotNull(name, "name").trim(); name = requireNonNull(name, "name").trim();
if (name.isEmpty()) { if (name.isEmpty()) {
throw new IllegalArgumentException("empty name"); throw new IllegalArgumentException("empty name");
} }
@ -56,7 +56,7 @@ public class DefaultCookie implements Cookie {
@Override @Override
public void setValue(String value) { public void setValue(String value) {
this.value = checkNotNull(value, "value"); this.value = requireNonNull(value, "value");
} }
@Override @Override

View File

@ -15,7 +15,7 @@
*/ */
package io.netty.handler.codec.http.cookie; package io.netty.handler.codec.http.cookie;
import static io.netty.util.internal.ObjectUtil.checkNotNull; import static java.util.Objects.requireNonNull;
import java.util.Collections; import java.util.Collections;
import java.util.Set; import java.util.Set;
@ -62,7 +62,7 @@ public final class ServerCookieDecoder extends CookieDecoder {
* @return the decoded {@link Cookie} * @return the decoded {@link Cookie}
*/ */
public Set<Cookie> decode(String header) { public Set<Cookie> decode(String header) {
final int headerLen = checkNotNull(header, "header").length(); final int headerLen = requireNonNull(header, "header").length();
if (headerLen == 0) { if (headerLen == 0) {
return Collections.emptySet(); return Collections.emptySet();

View File

@ -19,7 +19,7 @@ import static io.netty.handler.codec.http.cookie.CookieUtil.add;
import static io.netty.handler.codec.http.cookie.CookieUtil.addQuoted; import static io.netty.handler.codec.http.cookie.CookieUtil.addQuoted;
import static io.netty.handler.codec.http.cookie.CookieUtil.stringBuilder; import static io.netty.handler.codec.http.cookie.CookieUtil.stringBuilder;
import static io.netty.handler.codec.http.cookie.CookieUtil.stripTrailingSeparator; import static io.netty.handler.codec.http.cookie.CookieUtil.stripTrailingSeparator;
import static io.netty.util.internal.ObjectUtil.checkNotNull; import static java.util.Objects.requireNonNull;
import io.netty.handler.codec.DateFormatter; import io.netty.handler.codec.DateFormatter;
import io.netty.handler.codec.http.HttpConstants; import io.netty.handler.codec.http.HttpConstants;
@ -88,7 +88,7 @@ public final class ServerCookieEncoder extends CookieEncoder {
* @return a single Set-Cookie header value * @return a single Set-Cookie header value
*/ */
public String encode(Cookie cookie) { public String encode(Cookie cookie) {
final String name = checkNotNull(cookie, "cookie").name(); final String name = requireNonNull(cookie, "cookie").name();
final String value = cookie.value() != null ? cookie.value() : ""; final String value = cookie.value() != null ? cookie.value() : "";
validateCookie(name, value); validateCookie(name, value);
@ -155,7 +155,7 @@ public final class ServerCookieEncoder extends CookieEncoder {
* @return the corresponding bunch of Set-Cookie headers * @return the corresponding bunch of Set-Cookie headers
*/ */
public List<String> encode(Cookie... cookies) { public List<String> encode(Cookie... cookies) {
if (checkNotNull(cookies, "cookies").length == 0) { if (requireNonNull(cookies, "cookies").length == 0) {
return Collections.emptyList(); return Collections.emptyList();
} }
@ -179,7 +179,7 @@ public final class ServerCookieEncoder extends CookieEncoder {
* @return the corresponding bunch of Set-Cookie headers * @return the corresponding bunch of Set-Cookie headers
*/ */
public List<String> encode(Collection<? extends Cookie> cookies) { public List<String> encode(Collection<? extends Cookie> cookies) {
if (checkNotNull(cookies, "cookies").isEmpty()) { if (requireNonNull(cookies, "cookies").isEmpty()) {
return Collections.emptyList(); return Collections.emptyList();
} }
@ -203,7 +203,7 @@ public final class ServerCookieEncoder extends CookieEncoder {
* @return the corresponding bunch of Set-Cookie headers * @return the corresponding bunch of Set-Cookie headers
*/ */
public List<String> encode(Iterable<? extends Cookie> cookies) { public List<String> encode(Iterable<? extends Cookie> cookies) {
Iterator<? extends Cookie> cookiesIt = checkNotNull(cookies, "cookies").iterator(); Iterator<? extends Cookie> cookiesIt = requireNonNull(cookies, "cookies").iterator();
if (!cookiesIt.hasNext()) { if (!cookiesIt.hasNext()) {
return Collections.emptyList(); return Collections.emptyList();
} }

View File

@ -38,7 +38,7 @@ import static io.netty.handler.codec.http.HttpResponseStatus.FORBIDDEN;
import static io.netty.handler.codec.http.HttpResponseStatus.OK; import static io.netty.handler.codec.http.HttpResponseStatus.OK;
import static io.netty.util.ReferenceCountUtil.release; import static io.netty.util.ReferenceCountUtil.release;
import static io.netty.util.internal.ObjectUtil.checkNonEmpty; import static io.netty.util.internal.ObjectUtil.checkNonEmpty;
import static io.netty.util.internal.ObjectUtil.checkNotNull; import static java.util.Objects.requireNonNull;
/** /**
* Handles <a href="http://www.w3.org/TR/cors/">Cross Origin Resource Sharing</a> (CORS) requests. * Handles <a href="http://www.w3.org/TR/cors/">Cross Origin Resource Sharing</a> (CORS) requests.
@ -61,7 +61,7 @@ public class CorsHandler extends ChannelDuplexHandler {
* Creates a new instance with a single {@link CorsConfig}. * Creates a new instance with a single {@link CorsConfig}.
*/ */
public CorsHandler(final CorsConfig config) { public CorsHandler(final CorsConfig config) {
this(Collections.singletonList(checkNotNull(config, "config")), config.isShortCircuit()); this(Collections.singletonList(requireNonNull(config, "config")), config.isShortCircuit());
} }
/** /**

View File

@ -32,6 +32,7 @@ import java.nio.charset.Charset;
import java.nio.file.Files; import java.nio.file.Files;
import static io.netty.buffer.Unpooled.*; import static io.netty.buffer.Unpooled.*;
import static java.util.Objects.requireNonNull;
/** /**
* Abstract Disk HttpData implementation * Abstract Disk HttpData implementation
@ -101,9 +102,7 @@ public abstract class AbstractDiskHttpData extends AbstractHttpData {
@Override @Override
public void setContent(ByteBuf buffer) throws IOException { public void setContent(ByteBuf buffer) throws IOException {
if (buffer == null) { requireNonNull(buffer, "buffer");
throw new NullPointerException("buffer");
}
try { try {
size = buffer.readableBytes(); size = buffer.readableBytes();
checkSize(size); checkSize(size);
@ -188,9 +187,7 @@ public abstract class AbstractDiskHttpData extends AbstractHttpData {
fileChannel = null; fileChannel = null;
setCompleted(); setCompleted();
} else { } else {
if (buffer == null) { requireNonNull(buffer, "buffer");
throw new NullPointerException("buffer");
}
} }
} }
@ -208,9 +205,7 @@ public abstract class AbstractDiskHttpData extends AbstractHttpData {
@Override @Override
public void setContent(InputStream inputStream) throws IOException { public void setContent(InputStream inputStream) throws IOException {
if (inputStream == null) { requireNonNull(inputStream, "inputStream");
throw new NullPointerException("inputStream");
}
if (file != null) { if (file != null) {
delete(); delete();
} }
@ -335,9 +330,7 @@ public abstract class AbstractDiskHttpData extends AbstractHttpData {
@Override @Override
public boolean renameTo(File dest) throws IOException { public boolean renameTo(File dest) throws IOException {
if (dest == null) { requireNonNull(dest, "dest");
throw new NullPointerException("dest");
}
if (file == null) { if (file == null) {
throw new IOException("No file defined so cannot be renamed"); throw new IOException("No file defined so cannot be renamed");
} }

View File

@ -15,6 +15,8 @@
*/ */
package io.netty.handler.codec.http.multipart; package io.netty.handler.codec.http.multipart;
import static java.util.Objects.requireNonNull;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelException; import io.netty.channel.ChannelException;
import io.netty.handler.codec.http.HttpConstants; import io.netty.handler.codec.http.HttpConstants;
@ -40,9 +42,7 @@ public abstract class AbstractHttpData extends AbstractReferenceCounted implemen
private long maxSize = DefaultHttpDataFactory.MAXSIZE; private long maxSize = DefaultHttpDataFactory.MAXSIZE;
protected AbstractHttpData(String name, Charset charset, long size) { protected AbstractHttpData(String name, Charset charset, long size) {
if (name == null) { requireNonNull(name, "name");
throw new NullPointerException("name");
}
name = REPLACE_PATTERN.matcher(name).replaceAll(" "); name = REPLACE_PATTERN.matcher(name).replaceAll(" ");
name = STRIP_PATTERN.matcher(name).replaceAll(""); name = STRIP_PATTERN.matcher(name).replaceAll("");
@ -96,9 +96,7 @@ public abstract class AbstractHttpData extends AbstractReferenceCounted implemen
@Override @Override
public void setCharset(Charset charset) { public void setCharset(Charset charset) {
if (charset == null) { requireNonNull(charset, "charset");
throw new NullPointerException("charset");
}
this.charset = charset; this.charset = charset;
} }

View File

@ -32,6 +32,7 @@ import static io.netty.buffer.Unpooled.EMPTY_BUFFER;
import static io.netty.buffer.Unpooled.buffer; import static io.netty.buffer.Unpooled.buffer;
import static io.netty.buffer.Unpooled.compositeBuffer; import static io.netty.buffer.Unpooled.compositeBuffer;
import static io.netty.buffer.Unpooled.wrappedBuffer; import static io.netty.buffer.Unpooled.wrappedBuffer;
import static java.util.Objects.requireNonNull;
/** /**
* Abstract Memory HttpData implementation * Abstract Memory HttpData implementation
@ -47,9 +48,7 @@ public abstract class AbstractMemoryHttpData extends AbstractHttpData {
@Override @Override
public void setContent(ByteBuf buffer) throws IOException { public void setContent(ByteBuf buffer) throws IOException {
if (buffer == null) { requireNonNull(buffer, "buffer");
throw new NullPointerException("buffer");
}
long localsize = buffer.readableBytes(); long localsize = buffer.readableBytes();
checkSize(localsize); checkSize(localsize);
if (definedSize > 0 && definedSize < localsize) { if (definedSize > 0 && definedSize < localsize) {
@ -66,9 +65,7 @@ public abstract class AbstractMemoryHttpData extends AbstractHttpData {
@Override @Override
public void setContent(InputStream inputStream) throws IOException { public void setContent(InputStream inputStream) throws IOException {
if (inputStream == null) { requireNonNull(inputStream, "inputStream");
throw new NullPointerException("inputStream");
}
ByteBuf buffer = buffer(); ByteBuf buffer = buffer();
byte[] bytes = new byte[4096 * 4]; byte[] bytes = new byte[4096 * 4];
int read = inputStream.read(bytes); int read = inputStream.read(bytes);
@ -115,17 +112,13 @@ public abstract class AbstractMemoryHttpData extends AbstractHttpData {
if (last) { if (last) {
setCompleted(); setCompleted();
} else { } else {
if (buffer == null) { requireNonNull(buffer, "buffer");
throw new NullPointerException("buffer");
}
} }
} }
@Override @Override
public void setContent(File file) throws IOException { public void setContent(File file) throws IOException {
if (file == null) { requireNonNull(file, "file");
throw new NullPointerException("file");
}
long newsize = file.length(); long newsize = file.length();
if (newsize > Integer.MAX_VALUE) { if (newsize > Integer.MAX_VALUE) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
@ -222,9 +215,7 @@ public abstract class AbstractMemoryHttpData extends AbstractHttpData {
@Override @Override
public boolean renameTo(File dest) throws IOException { public boolean renameTo(File dest) throws IOException {
if (dest == null) { requireNonNull(dest, "dest");
throw new NullPointerException("dest");
}
if (byteBuf == null) { if (byteBuf == null) {
// empty file // empty file
if (!dest.createNewFile()) { if (!dest.createNewFile()) {

View File

@ -23,6 +23,7 @@ import java.io.IOException;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import static io.netty.buffer.Unpooled.wrappedBuffer; import static io.netty.buffer.Unpooled.wrappedBuffer;
import static java.util.Objects.requireNonNull;
/** /**
* Disk implementation of Attributes * Disk implementation of Attributes
@ -77,9 +78,7 @@ public class DiskAttribute extends AbstractDiskHttpData implements Attribute {
@Override @Override
public void setValue(String value) throws IOException { public void setValue(String value) throws IOException {
if (value == null) { requireNonNull(value, "value");
throw new NullPointerException("value");
}
byte [] bytes = value.getBytes(getCharset()); byte [] bytes = value.getBytes(getCharset());
checkSize(bytes.length); checkSize(bytes.length);
ByteBuf buffer = wrappedBuffer(bytes); ByteBuf buffer = wrappedBuffer(bytes);

View File

@ -15,6 +15,8 @@
*/ */
package io.netty.handler.codec.http.multipart; package io.netty.handler.codec.http.multipart;
import static java.util.Objects.requireNonNull;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelException; import io.netty.channel.ChannelException;
import io.netty.handler.codec.http.HttpHeaderNames; import io.netty.handler.codec.http.HttpHeaderNames;
@ -62,9 +64,7 @@ public class DiskFileUpload extends AbstractDiskHttpData implements FileUpload {
@Override @Override
public void setFilename(String filename) { public void setFilename(String filename) {
if (filename == null) { requireNonNull(filename, "filename");
throw new NullPointerException("filename");
}
this.filename = filename; this.filename = filename;
} }
@ -93,9 +93,7 @@ public class DiskFileUpload extends AbstractDiskHttpData implements FileUpload {
@Override @Override
public void setContentType(String contentType) { public void setContentType(String contentType) {
if (contentType == null) { requireNonNull(contentType, "contentType");
throw new NullPointerException("contentType");
}
this.contentType = contentType; this.contentType = contentType;
} }

View File

@ -45,8 +45,8 @@ import static io.netty.buffer.Unpooled.buffer;
import static io.netty.handler.codec.http.multipart.HttpPostBodyUtil.BINARY_STRING; import static io.netty.handler.codec.http.multipart.HttpPostBodyUtil.BINARY_STRING;
import static io.netty.handler.codec.http.multipart.HttpPostBodyUtil.BIT_7_STRING; import static io.netty.handler.codec.http.multipart.HttpPostBodyUtil.BIT_7_STRING;
import static io.netty.handler.codec.http.multipart.HttpPostBodyUtil.BIT_8_STRING; import static io.netty.handler.codec.http.multipart.HttpPostBodyUtil.BIT_8_STRING;
import static io.netty.util.internal.ObjectUtil.checkNotNull;
import static io.netty.util.internal.ObjectUtil.checkPositiveOrZero; import static io.netty.util.internal.ObjectUtil.checkPositiveOrZero;
import static java.util.Objects.requireNonNull;
/** /**
* This decoder will decode Body and can handle POST BODY. * This decoder will decode Body and can handle POST BODY.
@ -177,9 +177,9 @@ public class HttpPostMultipartRequestDecoder implements InterfaceHttpPostRequest
* errors * errors
*/ */
public HttpPostMultipartRequestDecoder(HttpDataFactory factory, HttpRequest request, Charset charset) { public HttpPostMultipartRequestDecoder(HttpDataFactory factory, HttpRequest request, Charset charset) {
this.request = checkNotNull(request, "request"); this.request = requireNonNull(request, "request");
this.charset = checkNotNull(charset, "charset"); this.charset = requireNonNull(charset, "charset");
this.factory = checkNotNull(factory, "factory"); this.factory = requireNonNull(factory, "factory");
// Fill default values // Fill default values
setMultipart(this.request.headers().get(HttpHeaderNames.CONTENT_TYPE)); setMultipart(this.request.headers().get(HttpHeaderNames.CONTENT_TYPE));

View File

@ -15,6 +15,8 @@
*/ */
package io.netty.handler.codec.http.multipart; package io.netty.handler.codec.http.multipart;
import static java.util.Objects.requireNonNull;
import io.netty.handler.codec.DecoderException; import io.netty.handler.codec.DecoderException;
import io.netty.handler.codec.http.HttpConstants; import io.netty.handler.codec.http.HttpConstants;
import io.netty.handler.codec.http.HttpContent; import io.netty.handler.codec.http.HttpContent;
@ -83,15 +85,9 @@ public class HttpPostRequestDecoder implements InterfaceHttpPostRequestDecoder {
* errors * errors
*/ */
public HttpPostRequestDecoder(HttpDataFactory factory, HttpRequest request, Charset charset) { public HttpPostRequestDecoder(HttpDataFactory factory, HttpRequest request, Charset charset) {
if (factory == null) { requireNonNull(factory, "factory");
throw new NullPointerException("factory"); requireNonNull(request, "request");
} requireNonNull(charset, "charset");
if (request == null) {
throw new NullPointerException("request");
}
if (charset == null) {
throw new NullPointerException("charset");
}
// Fill default values // Fill default values
if (isMultipart(request)) { if (isMultipart(request)) {
decoder = new HttpPostMultipartRequestDecoder(factory, request, charset); decoder = new HttpPostMultipartRequestDecoder(factory, request, charset);

View File

@ -49,8 +49,8 @@ import java.util.concurrent.ThreadLocalRandom;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import static io.netty.buffer.Unpooled.wrappedBuffer; import static io.netty.buffer.Unpooled.wrappedBuffer;
import static io.netty.util.internal.ObjectUtil.checkNotNull;
import static java.util.AbstractMap.SimpleImmutableEntry; import static java.util.AbstractMap.SimpleImmutableEntry;
import static java.util.Objects.requireNonNull;
/** /**
* This encoder will help to encode Request for a FORM as POST. * This encoder will help to encode Request for a FORM as POST.
@ -209,9 +209,9 @@ public class HttpPostRequestEncoder implements ChunkedInput<HttpContent> {
HttpDataFactory factory, HttpRequest request, boolean multipart, Charset charset, HttpDataFactory factory, HttpRequest request, boolean multipart, Charset charset,
EncoderMode encoderMode) EncoderMode encoderMode)
throws ErrorDataEncoderException { throws ErrorDataEncoderException {
this.request = checkNotNull(request, "request"); this.request = requireNonNull(request, "request");
this.charset = checkNotNull(charset, "charset"); this.charset = requireNonNull(charset, "charset");
this.factory = checkNotNull(factory, "factory"); this.factory = requireNonNull(factory, "factory");
if (HttpMethod.TRACE.equals(request.method())) { if (HttpMethod.TRACE.equals(request.method())) {
throw new ErrorDataEncoderException("Cannot create a Encoder if request is a TRACE"); throw new ErrorDataEncoderException("Cannot create a Encoder if request is a TRACE");
} }
@ -310,9 +310,7 @@ public class HttpPostRequestEncoder implements ChunkedInput<HttpContent> {
* if the encoding is in error or if the finalize were already done * if the encoding is in error or if the finalize were already done
*/ */
public void setBodyHttpDatas(List<InterfaceHttpData> datas) throws ErrorDataEncoderException { public void setBodyHttpDatas(List<InterfaceHttpData> datas) throws ErrorDataEncoderException {
if (datas == null) { requireNonNull(datas, "datas");
throw new NullPointerException("datas");
}
globalBodySize = 0; globalBodySize = 0;
bodyListDatas.clear(); bodyListDatas.clear();
currentFileUpload = null; currentFileUpload = null;
@ -337,7 +335,7 @@ public class HttpPostRequestEncoder implements ChunkedInput<HttpContent> {
*/ */
public void addBodyAttribute(String name, String value) throws ErrorDataEncoderException { public void addBodyAttribute(String name, String value) throws ErrorDataEncoderException {
String svalue = value != null? value : StringUtil.EMPTY_STRING; String svalue = value != null? value : StringUtil.EMPTY_STRING;
Attribute data = factory.createAttribute(request, checkNotNull(name, "name"), svalue); Attribute data = factory.createAttribute(request, requireNonNull(name, "name"), svalue);
addBodyHttpData(data); addBodyHttpData(data);
} }
@ -383,8 +381,8 @@ public class HttpPostRequestEncoder implements ChunkedInput<HttpContent> {
*/ */
public void addBodyFileUpload(String name, String filename, File file, String contentType, boolean isText) public void addBodyFileUpload(String name, String filename, File file, String contentType, boolean isText)
throws ErrorDataEncoderException { throws ErrorDataEncoderException {
checkNotNull(name, "name"); requireNonNull(name, "name");
checkNotNull(file, "file"); requireNonNull(file, "file");
if (filename == null) { if (filename == null) {
filename = StringUtil.EMPTY_STRING; filename = StringUtil.EMPTY_STRING;
} }
@ -448,7 +446,7 @@ public class HttpPostRequestEncoder implements ChunkedInput<HttpContent> {
if (headerFinalized) { if (headerFinalized) {
throw new ErrorDataEncoderException("Cannot add value once finalized"); throw new ErrorDataEncoderException("Cannot add value once finalized");
} }
bodyListDatas.add(checkNotNull(data, "data")); bodyListDatas.add(requireNonNull(data, "data"));
if (!isMultipart) { if (!isMultipart) {
if (data instanceof Attribute) { if (data instanceof Attribute) {
Attribute attribute = (Attribute) data; Attribute attribute = (Attribute) data;

View File

@ -35,7 +35,8 @@ import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
import static io.netty.buffer.Unpooled.*; import static io.netty.buffer.Unpooled.*;
import static io.netty.util.internal.ObjectUtil.*; import static io.netty.util.internal.ObjectUtil.checkPositiveOrZero;
import static java.util.Objects.requireNonNull;
/** /**
* This decoder will decode Body and can handle POST BODY. * This decoder will decode Body and can handle POST BODY.
@ -145,9 +146,9 @@ public class HttpPostStandardRequestDecoder implements InterfaceHttpPostRequestD
* errors * errors
*/ */
public HttpPostStandardRequestDecoder(HttpDataFactory factory, HttpRequest request, Charset charset) { public HttpPostStandardRequestDecoder(HttpDataFactory factory, HttpRequest request, Charset charset) {
this.request = checkNotNull(request, "request"); this.request = requireNonNull(request, "request");
this.charset = checkNotNull(charset, "charset"); this.charset = requireNonNull(charset, "charset");
this.factory = checkNotNull(factory, "factory"); this.factory = requireNonNull(factory, "factory");
if (request instanceof HttpContent) { if (request instanceof HttpContent) {
// Offer automatically if the given request is als type of HttpContent // Offer automatically if the given request is als type of HttpContent
// See #1089 // See #1089

View File

@ -15,6 +15,8 @@
*/ */
package io.netty.handler.codec.http.multipart; package io.netty.handler.codec.http.multipart;
import static java.util.Objects.requireNonNull;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import io.netty.util.AbstractReferenceCounted; import io.netty.util.AbstractReferenceCounted;
@ -42,27 +44,21 @@ final class InternalAttribute extends AbstractReferenceCounted implements Interf
} }
public void addValue(String value) { public void addValue(String value) {
if (value == null) { requireNonNull(value, "value");
throw new NullPointerException("value");
}
ByteBuf buf = Unpooled.copiedBuffer(value, charset); ByteBuf buf = Unpooled.copiedBuffer(value, charset);
this.value.add(buf); this.value.add(buf);
size += buf.readableBytes(); size += buf.readableBytes();
} }
public void addValue(String value, int rank) { public void addValue(String value, int rank) {
if (value == null) { requireNonNull(value, "value");
throw new NullPointerException("value");
}
ByteBuf buf = Unpooled.copiedBuffer(value, charset); ByteBuf buf = Unpooled.copiedBuffer(value, charset);
this.value.add(rank, buf); this.value.add(rank, buf);
size += buf.readableBytes(); size += buf.readableBytes();
} }
public void setValue(String value, int rank) { public void setValue(String value, int rank) {
if (value == null) { requireNonNull(value, "value");
throw new NullPointerException("value");
}
ByteBuf buf = Unpooled.copiedBuffer(value, charset); ByteBuf buf = Unpooled.copiedBuffer(value, charset);
ByteBuf old = this.value.set(rank, buf); ByteBuf old = this.value.set(rank, buf);
if (old != null) { if (old != null) {

View File

@ -23,6 +23,7 @@ import java.io.IOException;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import static io.netty.buffer.Unpooled.*; import static io.netty.buffer.Unpooled.*;
import static java.util.Objects.requireNonNull;
/** /**
* Memory implementation of Attributes * Memory implementation of Attributes
@ -66,9 +67,7 @@ public class MemoryAttribute extends AbstractMemoryHttpData implements Attribute
@Override @Override
public void setValue(String value) throws IOException { public void setValue(String value) throws IOException {
if (value == null) { requireNonNull(value, "value");
throw new NullPointerException("value");
}
byte [] bytes = value.getBytes(getCharset()); byte [] bytes = value.getBytes(getCharset());
checkSize(bytes.length); checkSize(bytes.length);
ByteBuf buffer = wrappedBuffer(bytes); ByteBuf buffer = wrappedBuffer(bytes);

View File

@ -15,6 +15,8 @@
*/ */
package io.netty.handler.codec.http.multipart; package io.netty.handler.codec.http.multipart;
import static java.util.Objects.requireNonNull;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelException; import io.netty.channel.ChannelException;
import io.netty.handler.codec.http.HttpHeaderNames; import io.netty.handler.codec.http.HttpHeaderNames;
@ -56,9 +58,7 @@ public class MemoryFileUpload extends AbstractMemoryHttpData implements FileUplo
@Override @Override
public void setFilename(String filename) { public void setFilename(String filename) {
if (filename == null) { requireNonNull(filename, "filename");
throw new NullPointerException("filename");
}
this.filename = filename; this.filename = filename;
} }
@ -87,9 +87,7 @@ public class MemoryFileUpload extends AbstractMemoryHttpData implements FileUplo
@Override @Override
public void setContentType(String contentType) { public void setContentType(String contentType) {
if (contentType == null) { requireNonNull(contentType, "contentType");
throw new NullPointerException("contentType");
}
this.contentType = contentType; this.contentType = contentType;
} }

View File

@ -15,11 +15,12 @@
*/ */
package io.netty.handler.codec.http.websocketx; package io.netty.handler.codec.http.websocketx;
import static java.util.Objects.requireNonNull;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator; import io.netty.buffer.ByteBufAllocator;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.stream.ChunkedInput; import io.netty.handler.stream.ChunkedInput;
import io.netty.util.internal.ObjectUtil;
/** /**
* A {@link ChunkedInput} that fetches data chunk by chunk for use with WebSocket chunked transfers. * A {@link ChunkedInput} that fetches data chunk by chunk for use with WebSocket chunked transfers.
@ -48,7 +49,7 @@ public final class WebSocketChunkedInput implements ChunkedInput<WebSocketFrame>
* @throws NullPointerException if {@code input} is null * @throws NullPointerException if {@code input} is null
*/ */
public WebSocketChunkedInput(ChunkedInput<ByteBuf> input, int rsv) { public WebSocketChunkedInput(ChunkedInput<ByteBuf> input, int rsv) {
this.input = ObjectUtil.checkNotNull(input, "input"); this.input = requireNonNull(input, "input");
this.rsv = rsv; this.rsv = rsv;
} }

View File

@ -15,6 +15,8 @@
*/ */
package io.netty.handler.codec.http.websocketx; package io.netty.handler.codec.http.websocketx;
import static java.util.Objects.requireNonNull;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelFutureListener;
@ -147,9 +149,7 @@ public abstract class WebSocketClientHandshaker {
* Channel * Channel
*/ */
public ChannelFuture handshake(Channel channel) { public ChannelFuture handshake(Channel channel) {
if (channel == null) { requireNonNull(channel, "channel");
throw new NullPointerException("channel");
}
return handshake(channel, channel.newPromise()); return handshake(channel, channel.newPromise());
} }
@ -398,9 +398,7 @@ public abstract class WebSocketClientHandshaker {
* Closing Frame that was received * Closing Frame that was received
*/ */
public ChannelFuture close(Channel channel, CloseWebSocketFrame frame) { public ChannelFuture close(Channel channel, CloseWebSocketFrame frame) {
if (channel == null) { requireNonNull(channel, "channel");
throw new NullPointerException("channel");
}
return close(channel, frame, channel.newPromise()); return close(channel, frame, channel.newPromise());
} }
@ -415,9 +413,7 @@ public abstract class WebSocketClientHandshaker {
* the {@link ChannelPromise} to be notified when the closing handshake is done * the {@link ChannelPromise} to be notified when the closing handshake is done
*/ */
public ChannelFuture close(Channel channel, CloseWebSocketFrame frame, ChannelPromise promise) { public ChannelFuture close(Channel channel, CloseWebSocketFrame frame, ChannelPromise promise) {
if (channel == null) { requireNonNull(channel, "channel");
throw new NullPointerException("channel");
}
return channel.writeAndFlush(frame, promise); return channel.writeAndFlush(frame, promise);
} }

View File

@ -15,6 +15,8 @@
*/ */
package io.netty.handler.codec.http.websocketx; package io.netty.handler.codec.http.websocketx;
import static java.util.Objects.requireNonNull;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelFutureListener;
@ -305,9 +307,7 @@ public abstract class WebSocketServerHandshaker {
* Closing Frame that was received * Closing Frame that was received
*/ */
public ChannelFuture close(Channel channel, CloseWebSocketFrame frame) { public ChannelFuture close(Channel channel, CloseWebSocketFrame frame) {
if (channel == null) { requireNonNull(channel, "channel");
throw new NullPointerException("channel");
}
return close(channel, frame, channel.newPromise()); return close(channel, frame, channel.newPromise());
} }
@ -322,9 +322,7 @@ public abstract class WebSocketServerHandshaker {
* the {@link ChannelPromise} to be notified when the closing handshake is done * the {@link ChannelPromise} to be notified when the closing handshake is done
*/ */
public ChannelFuture close(Channel channel, CloseWebSocketFrame frame, ChannelPromise promise) { public ChannelFuture close(Channel channel, CloseWebSocketFrame frame, ChannelPromise promise) {
if (channel == null) { requireNonNull(channel, "channel");
throw new NullPointerException("channel");
}
return channel.writeAndFlush(frame, promise).addListener(ChannelFutureListener.CLOSE); return channel.writeAndFlush(frame, promise).addListener(ChannelFutureListener.CLOSE);
} }

View File

@ -15,6 +15,8 @@
*/ */
package io.netty.handler.codec.http.websocketx.extensions; package io.netty.handler.codec.http.websocketx.extensions;
import static java.util.Objects.requireNonNull;
import io.netty.channel.ChannelDuplexHandler; import io.netty.channel.ChannelDuplexHandler;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPromise; import io.netty.channel.ChannelPromise;
@ -50,9 +52,7 @@ public class WebSocketClientExtensionHandler extends ChannelDuplexHandler {
* with fallback configuration. * with fallback configuration.
*/ */
public WebSocketClientExtensionHandler(WebSocketClientExtensionHandshaker... extensionHandshakers) { public WebSocketClientExtensionHandler(WebSocketClientExtensionHandshaker... extensionHandshakers) {
if (extensionHandshakers == null) { requireNonNull(extensionHandshakers, "extensionHandshakers");
throw new NullPointerException("extensionHandshakers");
}
if (extensionHandshakers.length == 0) { if (extensionHandshakers.length == 0) {
throw new IllegalArgumentException("extensionHandshakers must contains at least one handshaker"); throw new IllegalArgumentException("extensionHandshakers must contains at least one handshaker");
} }

View File

@ -15,6 +15,8 @@
*/ */
package io.netty.handler.codec.http.websocketx.extensions; package io.netty.handler.codec.http.websocketx.extensions;
import static java.util.Objects.requireNonNull;
import java.util.Collections; import java.util.Collections;
import java.util.Map; import java.util.Map;
@ -29,12 +31,8 @@ public final class WebSocketExtensionData {
private final Map<String, String> parameters; private final Map<String, String> parameters;
public WebSocketExtensionData(String name, Map<String, String> parameters) { public WebSocketExtensionData(String name, Map<String, String> parameters) {
if (name == null) { requireNonNull(name, "name");
throw new NullPointerException("name"); requireNonNull(parameters, "parameters");
}
if (parameters == null) {
throw new NullPointerException("parameters");
}
this.name = name; this.name = name;
this.parameters = Collections.unmodifiableMap(parameters); this.parameters = Collections.unmodifiableMap(parameters);
} }

View File

@ -15,8 +15,9 @@
*/ */
package io.netty.handler.codec.http.websocketx.extensions; package io.netty.handler.codec.http.websocketx.extensions;
import static java.util.Objects.requireNonNull;
import io.netty.channel.ChannelDuplexHandler; import io.netty.channel.ChannelDuplexHandler;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPromise; import io.netty.channel.ChannelPromise;
@ -53,9 +54,7 @@ public class WebSocketServerExtensionHandler extends ChannelDuplexHandler {
* with fallback configuration. * with fallback configuration.
*/ */
public WebSocketServerExtensionHandler(WebSocketServerExtensionHandshaker... extensionHandshakers) { public WebSocketServerExtensionHandler(WebSocketServerExtensionHandshaker... extensionHandshakers) {
if (extensionHandshakers == null) { requireNonNull(extensionHandshakers, "extensionHandshakers");
throw new NullPointerException("extensionHandshakers");
}
if (extensionHandshakers.length == 0) { if (extensionHandshakers.length == 0) {
throw new IllegalArgumentException("extensionHandshakers must contains at least one handshaker"); throw new IllegalArgumentException("extensionHandshakers must contains at least one handshaker");
} }

View File

@ -15,6 +15,8 @@
*/ */
package io.netty.handler.codec.rtsp; package io.netty.handler.codec.rtsp;
import static java.util.Objects.requireNonNull;
import io.netty.handler.codec.http.HttpMethod; import io.netty.handler.codec.http.HttpMethod;
import java.util.HashMap; import java.util.HashMap;
@ -117,9 +119,7 @@ public final class RtspMethods {
* will be returned. Otherwise, a new instance will be returned. * will be returned. Otherwise, a new instance will be returned.
*/ */
public static HttpMethod valueOf(String name) { public static HttpMethod valueOf(String name) {
if (name == null) { requireNonNull(name, "name");
throw new NullPointerException("name");
}
name = name.trim().toUpperCase(); name = name.trim().toUpperCase();
if (name.isEmpty()) { if (name.isEmpty()) {

View File

@ -15,6 +15,8 @@
*/ */
package io.netty.handler.codec.rtsp; package io.netty.handler.codec.rtsp;
import static java.util.Objects.requireNonNull;
import io.netty.handler.codec.http.HttpVersion; import io.netty.handler.codec.http.HttpVersion;
/** /**
@ -34,9 +36,7 @@ public final class RtspVersions {
* Otherwise, a new {@link HttpVersion} instance will be returned. * Otherwise, a new {@link HttpVersion} instance will be returned.
*/ */
public static HttpVersion valueOf(String text) { public static HttpVersion valueOf(String text) {
if (text == null) { requireNonNull(text, "text");
throw new NullPointerException("text");
}
text = text.trim().toUpperCase(); text = text.trim().toUpperCase();
if ("RTSP/1.0".equals(text)) { if ("RTSP/1.0".equals(text)) {

View File

@ -22,9 +22,9 @@ import io.netty.util.internal.UnstableApi;
import static io.netty.handler.codec.http2.Http2CodecUtil.DEFAULT_HEADER_LIST_SIZE; import static io.netty.handler.codec.http2.Http2CodecUtil.DEFAULT_HEADER_LIST_SIZE;
import static io.netty.handler.codec.http2.Http2CodecUtil.DEFAULT_INITIAL_HUFFMAN_DECODE_CAPACITY; import static io.netty.handler.codec.http2.Http2CodecUtil.DEFAULT_INITIAL_HUFFMAN_DECODE_CAPACITY;
import static io.netty.handler.codec.http2.Http2CodecUtil.DEFAULT_MAX_RESERVED_STREAMS; import static io.netty.handler.codec.http2.Http2CodecUtil.DEFAULT_MAX_RESERVED_STREAMS;
import static io.netty.util.internal.ObjectUtil.checkNotNull;
import static io.netty.util.internal.ObjectUtil.checkPositive; import static io.netty.util.internal.ObjectUtil.checkPositive;
import static io.netty.util.internal.ObjectUtil.checkPositiveOrZero; import static io.netty.util.internal.ObjectUtil.checkPositiveOrZero;
import static java.util.Objects.requireNonNull;
/** /**
* Abstract base class which defines commonly used features required to build {@link Http2ConnectionHandler} instances. * Abstract base class which defines commonly used features required to build {@link Http2ConnectionHandler} instances.
@ -116,7 +116,7 @@ public abstract class AbstractHttp2ConnectionHandlerBuilder<T extends Http2Conne
* Sets the {@link Http2Settings} to use for the initial connection settings exchange. * Sets the {@link Http2Settings} to use for the initial connection settings exchange.
*/ */
protected B initialSettings(Http2Settings settings) { protected B initialSettings(Http2Settings settings) {
initialSettings = checkNotNull(settings, "settings"); initialSettings = requireNonNull(settings, "settings");
return self(); return self();
} }
@ -134,7 +134,7 @@ public abstract class AbstractHttp2ConnectionHandlerBuilder<T extends Http2Conne
* This listener will only be set if the decoder's listener is {@code null}. * This listener will only be set if the decoder's listener is {@code null}.
*/ */
protected B frameListener(Http2FrameListener frameListener) { protected B frameListener(Http2FrameListener frameListener) {
this.frameListener = checkNotNull(frameListener, "frameListener"); this.frameListener = requireNonNull(frameListener, "frameListener");
return self(); return self();
} }
@ -220,7 +220,7 @@ public abstract class AbstractHttp2ConnectionHandlerBuilder<T extends Http2Conne
enforceConstraint("connection", "codec", decoder); enforceConstraint("connection", "codec", decoder);
enforceConstraint("connection", "codec", encoder); enforceConstraint("connection", "codec", encoder);
this.connection = checkNotNull(connection, "connection"); this.connection = requireNonNull(connection, "connection");
return self(); return self();
} }
@ -255,8 +255,8 @@ public abstract class AbstractHttp2ConnectionHandlerBuilder<T extends Http2Conne
enforceConstraint("codec", "headerSensitivityDetector", headerSensitivityDetector); enforceConstraint("codec", "headerSensitivityDetector", headerSensitivityDetector);
enforceConstraint("codec", "encoderEnforceMaxConcurrentStreams", encoderEnforceMaxConcurrentStreams); enforceConstraint("codec", "encoderEnforceMaxConcurrentStreams", encoderEnforceMaxConcurrentStreams);
checkNotNull(decoder, "decoder"); requireNonNull(decoder, "decoder");
checkNotNull(encoder, "encoder"); requireNonNull(encoder, "encoder");
if (decoder.connection() != encoder.connection()) { if (decoder.connection() != encoder.connection()) {
throw new IllegalArgumentException("The specified encoder and decoder have different connections."); throw new IllegalArgumentException("The specified encoder and decoder have different connections.");
@ -300,7 +300,7 @@ public abstract class AbstractHttp2ConnectionHandlerBuilder<T extends Http2Conne
*/ */
protected B frameLogger(Http2FrameLogger frameLogger) { protected B frameLogger(Http2FrameLogger frameLogger) {
enforceNonCodecConstraints("frameLogger"); enforceNonCodecConstraints("frameLogger");
this.frameLogger = checkNotNull(frameLogger, "frameLogger"); this.frameLogger = requireNonNull(frameLogger, "frameLogger");
return self(); return self();
} }
@ -334,7 +334,7 @@ public abstract class AbstractHttp2ConnectionHandlerBuilder<T extends Http2Conne
*/ */
protected B headerSensitivityDetector(SensitivityDetector headerSensitivityDetector) { protected B headerSensitivityDetector(SensitivityDetector headerSensitivityDetector) {
enforceNonCodecConstraints("headerSensitivityDetector"); enforceNonCodecConstraints("headerSensitivityDetector");
this.headerSensitivityDetector = checkNotNull(headerSensitivityDetector, "headerSensitivityDetector"); this.headerSensitivityDetector = requireNonNull(headerSensitivityDetector, "headerSensitivityDetector");
return self(); return self();
} }

View File

@ -17,7 +17,7 @@ package io.netty.handler.codec.http2;
import io.netty.handler.codec.TooLongFrameException; import io.netty.handler.codec.TooLongFrameException;
import io.netty.util.internal.UnstableApi; import io.netty.util.internal.UnstableApi;
import static io.netty.util.internal.ObjectUtil.checkNotNull; import static java.util.Objects.requireNonNull;
/** /**
* A skeletal builder implementation of {@link InboundHttp2ToHttpAdapter} and its subtypes. * A skeletal builder implementation of {@link InboundHttp2ToHttpAdapter} and its subtypes.
@ -38,7 +38,7 @@ public abstract class AbstractInboundHttp2ToHttpAdapterBuilder<
* for the current connection * for the current connection
*/ */
protected AbstractInboundHttp2ToHttpAdapterBuilder(Http2Connection connection) { protected AbstractInboundHttp2ToHttpAdapterBuilder(Http2Connection connection) {
this.connection = checkNotNull(connection, "connection"); this.connection = requireNonNull(connection, "connection");
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")

View File

@ -30,7 +30,7 @@ import java.util.List;
import static io.netty.buffer.Unpooled.unreleasableBuffer; import static io.netty.buffer.Unpooled.unreleasableBuffer;
import static io.netty.handler.codec.http2.Http2CodecUtil.connectionPrefaceBuf; import static io.netty.handler.codec.http2.Http2CodecUtil.connectionPrefaceBuf;
import static io.netty.util.internal.ObjectUtil.checkNotNull; import static java.util.Objects.requireNonNull;
/** /**
* Performing cleartext upgrade, by h2c HTTP upgrade or Prior Knowledge. * Performing cleartext upgrade, by h2c HTTP upgrade or Prior Knowledge.
@ -58,9 +58,9 @@ public final class CleartextHttp2ServerUpgradeHandler extends ChannelHandlerAdap
public CleartextHttp2ServerUpgradeHandler(HttpServerCodec httpServerCodec, public CleartextHttp2ServerUpgradeHandler(HttpServerCodec httpServerCodec,
HttpServerUpgradeHandler httpServerUpgradeHandler, HttpServerUpgradeHandler httpServerUpgradeHandler,
ChannelHandler http2ServerHandler) { ChannelHandler http2ServerHandler) {
this.httpServerCodec = checkNotNull(httpServerCodec, "httpServerCodec"); this.httpServerCodec = requireNonNull(httpServerCodec, "httpServerCodec");
this.httpServerUpgradeHandler = checkNotNull(httpServerUpgradeHandler, "httpServerUpgradeHandler"); this.httpServerUpgradeHandler = requireNonNull(httpServerUpgradeHandler, "httpServerUpgradeHandler");
this.http2ServerHandler = checkNotNull(http2ServerHandler, "http2ServerHandler"); this.http2ServerHandler = requireNonNull(http2ServerHandler, "http2ServerHandler");
} }
@Override @Override

View File

@ -14,7 +14,7 @@
*/ */
package io.netty.handler.codec.http2; package io.netty.handler.codec.http2;
import static io.netty.util.internal.ObjectUtil.checkNotNull; import static java.util.Objects.requireNonNull;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
@ -30,7 +30,7 @@ public class DecoratingHttp2ConnectionDecoder implements Http2ConnectionDecoder
private final Http2ConnectionDecoder delegate; private final Http2ConnectionDecoder delegate;
public DecoratingHttp2ConnectionDecoder(Http2ConnectionDecoder delegate) { public DecoratingHttp2ConnectionDecoder(Http2ConnectionDecoder delegate) {
this.delegate = checkNotNull(delegate, "delegate"); this.delegate = requireNonNull(delegate, "delegate");
} }
@Override @Override

View File

@ -16,7 +16,7 @@ package io.netty.handler.codec.http2;
import io.netty.util.internal.UnstableApi; import io.netty.util.internal.UnstableApi;
import static io.netty.util.internal.ObjectUtil.checkNotNull; import static java.util.Objects.requireNonNull;
/** /**
* A decorator around another {@link Http2ConnectionEncoder} instance. * A decorator around another {@link Http2ConnectionEncoder} instance.
@ -27,7 +27,7 @@ public class DecoratingHttp2ConnectionEncoder extends DecoratingHttp2FrameWriter
public DecoratingHttp2ConnectionEncoder(Http2ConnectionEncoder delegate) { public DecoratingHttp2ConnectionEncoder(Http2ConnectionEncoder delegate) {
super(delegate); super(delegate);
this.delegate = checkNotNull(delegate, "delegate"); this.delegate = requireNonNull(delegate, "delegate");
} }
@Override @Override

View File

@ -20,7 +20,7 @@ import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPromise; import io.netty.channel.ChannelPromise;
import io.netty.util.internal.UnstableApi; import io.netty.util.internal.UnstableApi;
import static io.netty.util.internal.ObjectUtil.checkNotNull; import static java.util.Objects.requireNonNull;
/** /**
* Decorator around another {@link Http2FrameWriter} instance. * Decorator around another {@link Http2FrameWriter} instance.
@ -30,7 +30,7 @@ public class DecoratingHttp2FrameWriter implements Http2FrameWriter {
private final Http2FrameWriter delegate; private final Http2FrameWriter delegate;
public DecoratingHttp2FrameWriter(Http2FrameWriter delegate) { public DecoratingHttp2FrameWriter(Http2FrameWriter delegate) {
this.delegate = checkNotNull(delegate, "delegate"); this.delegate = requireNonNull(delegate, "delegate");
} }
@Override @Override

View File

@ -53,9 +53,9 @@ import static io.netty.handler.codec.http2.Http2Stream.State.IDLE;
import static io.netty.handler.codec.http2.Http2Stream.State.OPEN; import static io.netty.handler.codec.http2.Http2Stream.State.OPEN;
import static io.netty.handler.codec.http2.Http2Stream.State.RESERVED_LOCAL; import static io.netty.handler.codec.http2.Http2Stream.State.RESERVED_LOCAL;
import static io.netty.handler.codec.http2.Http2Stream.State.RESERVED_REMOTE; import static io.netty.handler.codec.http2.Http2Stream.State.RESERVED_REMOTE;
import static io.netty.util.internal.ObjectUtil.checkNotNull;
import static io.netty.util.internal.ObjectUtil.checkPositiveOrZero; import static io.netty.util.internal.ObjectUtil.checkPositiveOrZero;
import static java.lang.Integer.MAX_VALUE; import static java.lang.Integer.MAX_VALUE;
import static java.util.Objects.requireNonNull;
/** /**
* Simple implementation of {@link Http2Connection}. * Simple implementation of {@link Http2Connection}.
@ -118,7 +118,7 @@ public class DefaultHttp2Connection implements Http2Connection {
@Override @Override
public Future<Void> close(final Promise<Void> promise) { public Future<Void> close(final Promise<Void> promise) {
checkNotNull(promise, "promise"); requireNonNull(promise, "promise");
// Since we allow this method to be called multiple times, we must make sure that all the promises are notified // Since we allow this method to be called multiple times, we must make sure that all the promises are notified
// when all streams are removed and the close operation completes. // when all streams are removed and the close operation completes.
if (closePromise != null) { if (closePromise != null) {
@ -370,7 +370,7 @@ public class DefaultHttp2Connection implements Http2Connection {
* @throws IllegalArgumentException if the key was not created by this connection. * @throws IllegalArgumentException if the key was not created by this connection.
*/ */
final DefaultPropertyKey verifyKey(PropertyKey key) { final DefaultPropertyKey verifyKey(PropertyKey key) {
return checkNotNull((DefaultPropertyKey) key, "key").verifyConnection(this); return requireNonNull((DefaultPropertyKey) key, "key").verifyConnection(this);
} }
/** /**
@ -853,7 +853,7 @@ public class DefaultHttp2Connection implements Http2Connection {
@Override @Override
public void flowController(F flowController) { public void flowController(F flowController) {
this.flowController = checkNotNull(flowController, "flowController"); this.flowController = requireNonNull(flowController, "flowController");
} }
@Override @Override

View File

@ -34,9 +34,9 @@ import static io.netty.handler.codec.http2.Http2Exception.streamError;
import static io.netty.handler.codec.http2.Http2PromisedRequestVerifier.ALWAYS_VERIFY; import static io.netty.handler.codec.http2.Http2PromisedRequestVerifier.ALWAYS_VERIFY;
import static io.netty.handler.codec.http2.Http2Stream.State.CLOSED; import static io.netty.handler.codec.http2.Http2Stream.State.CLOSED;
import static io.netty.handler.codec.http2.Http2Stream.State.HALF_CLOSED_REMOTE; import static io.netty.handler.codec.http2.Http2Stream.State.HALF_CLOSED_REMOTE;
import static io.netty.util.internal.ObjectUtil.checkNotNull;
import static java.lang.Integer.MAX_VALUE; import static java.lang.Integer.MAX_VALUE;
import static java.lang.Math.min; import static java.lang.Math.min;
import static java.util.Objects.requireNonNull;
/** /**
* Provides the default implementation for processing inbound frame events and delegates to a * Provides the default implementation for processing inbound frame events and delegates to a
@ -68,10 +68,10 @@ public class DefaultHttp2ConnectionDecoder implements Http2ConnectionDecoder {
Http2ConnectionEncoder encoder, Http2ConnectionEncoder encoder,
Http2FrameReader frameReader, Http2FrameReader frameReader,
Http2PromisedRequestVerifier requestVerifier) { Http2PromisedRequestVerifier requestVerifier) {
this.connection = checkNotNull(connection, "connection"); this.connection = requireNonNull(connection, "connection");
this.frameReader = checkNotNull(frameReader, "frameReader"); this.frameReader = requireNonNull(frameReader, "frameReader");
this.encoder = checkNotNull(encoder, "encoder"); this.encoder = requireNonNull(encoder, "encoder");
this.requestVerifier = checkNotNull(requestVerifier, "requestVerifier"); this.requestVerifier = requireNonNull(requestVerifier, "requestVerifier");
if (connection.local().flowController() == null) { if (connection.local().flowController() == null) {
connection.local().flowController(new DefaultHttp2LocalFlowController(connection)); connection.local().flowController(new DefaultHttp2LocalFlowController(connection));
} }
@ -80,7 +80,7 @@ public class DefaultHttp2ConnectionDecoder implements Http2ConnectionDecoder {
@Override @Override
public void lifecycleManager(Http2LifecycleManager lifecycleManager) { public void lifecycleManager(Http2LifecycleManager lifecycleManager) {
this.lifecycleManager = checkNotNull(lifecycleManager, "lifecycleManager"); this.lifecycleManager = requireNonNull(lifecycleManager, "lifecycleManager");
} }
@Override @Override
@ -95,7 +95,7 @@ public class DefaultHttp2ConnectionDecoder implements Http2ConnectionDecoder {
@Override @Override
public void frameListener(Http2FrameListener listener) { public void frameListener(Http2FrameListener listener) {
this.listener = checkNotNull(listener, "listener"); this.listener = requireNonNull(listener, "listener");
} }
@Override @Override

View File

@ -29,9 +29,9 @@ import static io.netty.handler.codec.http.HttpStatusClass.INFORMATIONAL;
import static io.netty.handler.codec.http2.Http2CodecUtil.DEFAULT_PRIORITY_WEIGHT; import static io.netty.handler.codec.http2.Http2CodecUtil.DEFAULT_PRIORITY_WEIGHT;
import static io.netty.handler.codec.http2.Http2Error.PROTOCOL_ERROR; import static io.netty.handler.codec.http2.Http2Error.PROTOCOL_ERROR;
import static io.netty.handler.codec.http2.Http2Exception.connectionError; import static io.netty.handler.codec.http2.Http2Exception.connectionError;
import static io.netty.util.internal.ObjectUtil.checkNotNull;
import static java.lang.Integer.MAX_VALUE; import static java.lang.Integer.MAX_VALUE;
import static java.lang.Math.min; import static java.lang.Math.min;
import static java.util.Objects.requireNonNull;
/** /**
* Default implementation of {@link Http2ConnectionEncoder}. * Default implementation of {@link Http2ConnectionEncoder}.
@ -46,8 +46,8 @@ public class DefaultHttp2ConnectionEncoder implements Http2ConnectionEncoder {
private final ArrayDeque<Http2Settings> outstandingLocalSettingsQueue = new ArrayDeque<>(4); private final ArrayDeque<Http2Settings> outstandingLocalSettingsQueue = new ArrayDeque<>(4);
public DefaultHttp2ConnectionEncoder(Http2Connection connection, Http2FrameWriter frameWriter) { public DefaultHttp2ConnectionEncoder(Http2Connection connection, Http2FrameWriter frameWriter) {
this.connection = checkNotNull(connection, "connection"); this.connection = requireNonNull(connection, "connection");
this.frameWriter = checkNotNull(frameWriter, "frameWriter"); this.frameWriter = requireNonNull(frameWriter, "frameWriter");
if (connection.remote().flowController() == null) { if (connection.remote().flowController() == null) {
connection.remote().flowController(new DefaultHttp2RemoteFlowController(connection)); connection.remote().flowController(new DefaultHttp2RemoteFlowController(connection));
} }
@ -55,7 +55,7 @@ public class DefaultHttp2ConnectionEncoder implements Http2ConnectionEncoder {
@Override @Override
public void lifecycleManager(Http2LifecycleManager lifecycleManager) { public void lifecycleManager(Http2LifecycleManager lifecycleManager) {
this.lifecycleManager = checkNotNull(lifecycleManager, "lifecycleManager"); this.lifecycleManager = requireNonNull(lifecycleManager, "lifecycleManager");
} }
@Override @Override

View File

@ -22,7 +22,7 @@ import io.netty.util.internal.StringUtil;
import io.netty.util.internal.UnstableApi; import io.netty.util.internal.UnstableApi;
import static io.netty.handler.codec.http2.Http2CodecUtil.verifyPadding; import static io.netty.handler.codec.http2.Http2CodecUtil.verifyPadding;
import static io.netty.util.internal.ObjectUtil.checkNotNull; import static java.util.Objects.requireNonNull;
/** /**
* The default {@link Http2DataFrame} implementation. * The default {@link Http2DataFrame} implementation.
@ -71,7 +71,7 @@ public final class DefaultHttp2DataFrame extends AbstractHttp2StreamFrame implem
* 256 (inclusive). * 256 (inclusive).
*/ */
public DefaultHttp2DataFrame(ByteBuf content, boolean endStream, int padding) { public DefaultHttp2DataFrame(ByteBuf content, boolean endStream, int padding) {
this.content = checkNotNull(content, "content"); this.content = requireNonNull(content, "content");
this.endStream = endStream; this.endStream = endStream;
verifyPadding(padding); verifyPadding(padding);
this.padding = padding; this.padding = padding;

View File

@ -60,9 +60,9 @@ import static io.netty.handler.codec.http2.Http2FrameTypes.PUSH_PROMISE;
import static io.netty.handler.codec.http2.Http2FrameTypes.RST_STREAM; import static io.netty.handler.codec.http2.Http2FrameTypes.RST_STREAM;
import static io.netty.handler.codec.http2.Http2FrameTypes.SETTINGS; import static io.netty.handler.codec.http2.Http2FrameTypes.SETTINGS;
import static io.netty.handler.codec.http2.Http2FrameTypes.WINDOW_UPDATE; import static io.netty.handler.codec.http2.Http2FrameTypes.WINDOW_UPDATE;
import static io.netty.util.internal.ObjectUtil.checkNotNull;
import static java.lang.Math.max; import static java.lang.Math.max;
import static java.lang.Math.min; import static java.lang.Math.min;
import static java.util.Objects.requireNonNull;
/** /**
* A {@link Http2FrameWriter} that supports all frame types defined by the HTTP/2 specification. * A {@link Http2FrameWriter} that supports all frame types defined by the HTTP/2 specification.
@ -306,7 +306,7 @@ public class DefaultHttp2FrameWriter implements Http2FrameWriter, Http2FrameSize
public ChannelFuture writeSettings(ChannelHandlerContext ctx, Http2Settings settings, public ChannelFuture writeSettings(ChannelHandlerContext ctx, Http2Settings settings,
ChannelPromise promise) { ChannelPromise promise) {
try { try {
checkNotNull(settings, "settings"); requireNonNull(settings, "settings");
int payloadLength = SETTING_ENTRY_LENGTH * settings.size(); int payloadLength = SETTING_ENTRY_LENGTH * settings.size();
ByteBuf buf = ctx.alloc().buffer(FRAME_HEADER_LENGTH + settings.size() * SETTING_ENTRY_LENGTH); ByteBuf buf = ctx.alloc().buffer(FRAME_HEADER_LENGTH + settings.size() * SETTING_ENTRY_LENGTH);
writeFrameHeaderInternal(buf, payloadLength, SETTINGS, new Http2Flags(), 0); writeFrameHeaderInternal(buf, payloadLength, SETTINGS, new Http2Flags(), 0);

View File

@ -16,7 +16,6 @@
package io.netty.handler.codec.http2; package io.netty.handler.codec.http2;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.util.internal.ObjectUtil;
import io.netty.util.internal.UnstableApi; import io.netty.util.internal.UnstableApi;
import static io.netty.handler.codec.http2.Http2CodecUtil.DEFAULT_HEADER_LIST_SIZE; import static io.netty.handler.codec.http2.Http2CodecUtil.DEFAULT_HEADER_LIST_SIZE;
@ -24,6 +23,7 @@ import static io.netty.handler.codec.http2.Http2CodecUtil.DEFAULT_INITIAL_HUFFMA
import static io.netty.handler.codec.http2.Http2Error.COMPRESSION_ERROR; import static io.netty.handler.codec.http2.Http2Error.COMPRESSION_ERROR;
import static io.netty.handler.codec.http2.Http2Error.INTERNAL_ERROR; import static io.netty.handler.codec.http2.Http2Error.INTERNAL_ERROR;
import static io.netty.handler.codec.http2.Http2Exception.connectionError; import static io.netty.handler.codec.http2.Http2Exception.connectionError;
import static java.util.Objects.requireNonNull;
@UnstableApi @UnstableApi
public class DefaultHttp2HeadersDecoder implements Http2HeadersDecoder, Http2HeadersDecoder.Configuration { public class DefaultHttp2HeadersDecoder implements Http2HeadersDecoder, Http2HeadersDecoder.Configuration {
@ -79,7 +79,7 @@ public class DefaultHttp2HeadersDecoder implements Http2HeadersDecoder, Http2Hea
* for testing but violate the RFC if used outside the scope of testing. * for testing but violate the RFC if used outside the scope of testing.
*/ */
DefaultHttp2HeadersDecoder(boolean validateHeaders, HpackDecoder hpackDecoder) { DefaultHttp2HeadersDecoder(boolean validateHeaders, HpackDecoder hpackDecoder) {
this.hpackDecoder = ObjectUtil.checkNotNull(hpackDecoder, "hpackDecoder"); this.hpackDecoder = requireNonNull(hpackDecoder, "hpackDecoder");
this.validateHeaders = validateHeaders; this.validateHeaders = validateHeaders;
this.maxHeaderListSizeGoAway = this.maxHeaderListSizeGoAway =
Http2CodecUtil.calculateMaxHeaderListSizeGoAway(hpackDecoder.getMaxHeaderListSize()); Http2CodecUtil.calculateMaxHeaderListSizeGoAway(hpackDecoder.getMaxHeaderListSize());

View File

@ -21,7 +21,7 @@ import io.netty.util.internal.UnstableApi;
import static io.netty.handler.codec.http2.Http2Error.COMPRESSION_ERROR; import static io.netty.handler.codec.http2.Http2Error.COMPRESSION_ERROR;
import static io.netty.handler.codec.http2.Http2Exception.connectionError; import static io.netty.handler.codec.http2.Http2Exception.connectionError;
import static io.netty.util.internal.ObjectUtil.checkNotNull; import static java.util.Objects.requireNonNull;
@UnstableApi @UnstableApi
public class DefaultHttp2HeadersEncoder implements Http2HeadersEncoder, Http2HeadersEncoder.Configuration { public class DefaultHttp2HeadersEncoder implements Http2HeadersEncoder, Http2HeadersEncoder.Configuration {
@ -51,8 +51,8 @@ public class DefaultHttp2HeadersEncoder implements Http2HeadersEncoder, Http2Hea
* for testing but violate the RFC if used outside the scope of testing. * for testing but violate the RFC if used outside the scope of testing.
*/ */
DefaultHttp2HeadersEncoder(SensitivityDetector sensitivityDetector, HpackEncoder hpackEncoder) { DefaultHttp2HeadersEncoder(SensitivityDetector sensitivityDetector, HpackEncoder hpackEncoder) {
this.sensitivityDetector = checkNotNull(sensitivityDetector, "sensitiveDetector"); this.sensitivityDetector = requireNonNull(sensitivityDetector, "sensitiveDetector");
this.hpackEncoder = checkNotNull(hpackEncoder, "hpackEncoder"); this.hpackEncoder = requireNonNull(hpackEncoder, "hpackEncoder");
} }
@Override @Override

View File

@ -19,7 +19,7 @@ import io.netty.util.internal.StringUtil;
import io.netty.util.internal.UnstableApi; import io.netty.util.internal.UnstableApi;
import static io.netty.handler.codec.http2.Http2CodecUtil.verifyPadding; import static io.netty.handler.codec.http2.Http2CodecUtil.verifyPadding;
import static io.netty.util.internal.ObjectUtil.checkNotNull; import static java.util.Objects.requireNonNull;
/** /**
* The default {@link Http2HeadersFrame} implementation. * The default {@link Http2HeadersFrame} implementation.
@ -57,7 +57,7 @@ public final class DefaultHttp2HeadersFrame extends AbstractHttp2StreamFrame imp
* 256 (inclusive). * 256 (inclusive).
*/ */
public DefaultHttp2HeadersFrame(Http2Headers headers, boolean endStream, int padding) { public DefaultHttp2HeadersFrame(Http2Headers headers, boolean endStream, int padding) {
this.headers = checkNotNull(headers, "headers"); this.headers = requireNonNull(headers, "headers");
this.endStream = endStream; this.endStream = endStream;
verifyPadding(padding); verifyPadding(padding);
this.padding = padding; this.padding = padding;

View File

@ -23,9 +23,10 @@ import static io.netty.handler.codec.http2.Http2Error.FLOW_CONTROL_ERROR;
import static io.netty.handler.codec.http2.Http2Error.INTERNAL_ERROR; import static io.netty.handler.codec.http2.Http2Error.INTERNAL_ERROR;
import static io.netty.handler.codec.http2.Http2Exception.connectionError; import static io.netty.handler.codec.http2.Http2Exception.connectionError;
import static io.netty.handler.codec.http2.Http2Exception.streamError; import static io.netty.handler.codec.http2.Http2Exception.streamError;
import static io.netty.util.internal.ObjectUtil.checkNotNull;
import static java.lang.Math.max; import static java.lang.Math.max;
import static java.lang.Math.min; import static java.lang.Math.min;
import static java.util.Objects.requireNonNull;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http2.Http2Exception.CompositeStreamException; import io.netty.handler.codec.http2.Http2Exception.CompositeStreamException;
@ -74,7 +75,7 @@ public class DefaultHttp2LocalFlowController implements Http2LocalFlowController
public DefaultHttp2LocalFlowController(Http2Connection connection, public DefaultHttp2LocalFlowController(Http2Connection connection,
float windowUpdateRatio, float windowUpdateRatio,
boolean autoRefillConnectionWindow) { boolean autoRefillConnectionWindow) {
this.connection = checkNotNull(connection, "connection"); this.connection = requireNonNull(connection, "connection");
windowUpdateRatio(windowUpdateRatio); windowUpdateRatio(windowUpdateRatio);
// Add a flow state for the connection. // Add a flow state for the connection.
@ -125,13 +126,13 @@ public class DefaultHttp2LocalFlowController implements Http2LocalFlowController
@Override @Override
public DefaultHttp2LocalFlowController frameWriter(Http2FrameWriter frameWriter) { public DefaultHttp2LocalFlowController frameWriter(Http2FrameWriter frameWriter) {
this.frameWriter = checkNotNull(frameWriter, "frameWriter"); this.frameWriter = requireNonNull(frameWriter, "frameWriter");
return this; return this;
} }
@Override @Override
public void channelHandlerContext(ChannelHandlerContext ctx) { public void channelHandlerContext(ChannelHandlerContext ctx) {
this.ctx = checkNotNull(ctx, "ctx"); this.ctx = requireNonNull(ctx, "ctx");
} }
@Override @Override

View File

@ -30,9 +30,9 @@ import static io.netty.handler.codec.http2.Http2Error.INTERNAL_ERROR;
import static io.netty.handler.codec.http2.Http2Error.STREAM_CLOSED; import static io.netty.handler.codec.http2.Http2Error.STREAM_CLOSED;
import static io.netty.handler.codec.http2.Http2Exception.streamError; import static io.netty.handler.codec.http2.Http2Exception.streamError;
import static io.netty.handler.codec.http2.Http2Stream.State.HALF_CLOSED_LOCAL; import static io.netty.handler.codec.http2.Http2Stream.State.HALF_CLOSED_LOCAL;
import static io.netty.util.internal.ObjectUtil.checkNotNull;
import static java.lang.Math.max; import static java.lang.Math.max;
import static java.lang.Math.min; import static java.lang.Math.min;
import static java.util.Objects.requireNonNull;
/** /**
* Basic implementation of {@link Http2RemoteFlowController}. * Basic implementation of {@link Http2RemoteFlowController}.
@ -69,8 +69,8 @@ public class DefaultHttp2RemoteFlowController implements Http2RemoteFlowControll
public DefaultHttp2RemoteFlowController(Http2Connection connection, public DefaultHttp2RemoteFlowController(Http2Connection connection,
StreamByteDistributor streamByteDistributor, StreamByteDistributor streamByteDistributor,
final Listener listener) { final Listener listener) {
this.connection = checkNotNull(connection, "connection"); this.connection = requireNonNull(connection, "connection");
this.streamByteDistributor = checkNotNull(streamByteDistributor, "streamWriteDistributor"); this.streamByteDistributor = requireNonNull(streamByteDistributor, "streamWriteDistributor");
// Add a flow state for the connection. // Add a flow state for the connection.
stateKey = connection.newKey(); stateKey = connection.newKey();
@ -131,7 +131,7 @@ public class DefaultHttp2RemoteFlowController implements Http2RemoteFlowControll
*/ */
@Override @Override
public void channelHandlerContext(ChannelHandlerContext ctx) throws Http2Exception { public void channelHandlerContext(ChannelHandlerContext ctx) throws Http2Exception {
this.ctx = checkNotNull(ctx, "ctx"); this.ctx = requireNonNull(ctx, "ctx");
// Writing the pending bytes will not check writability change and instead a writability change notification // Writing the pending bytes will not check writability change and instead a writability change notification
// to be provided by an explicit call. // to be provided by an explicit call.
@ -210,7 +210,7 @@ public class DefaultHttp2RemoteFlowController implements Http2RemoteFlowControll
public void addFlowControlled(Http2Stream stream, FlowControlled frame) { public void addFlowControlled(Http2Stream stream, FlowControlled frame) {
// The context can be null assuming the frame will be queued and send later when the context is set. // The context can be null assuming the frame will be queued and send later when the context is set.
assert ctx == null || ctx.executor().inEventLoop(); assert ctx == null || ctx.executor().inEventLoop();
checkNotNull(frame, "frame"); requireNonNull(frame, "frame");
try { try {
monitor.enqueueFrame(state(stream), frame); monitor.enqueueFrame(state(stream), frame);
} catch (Throwable t) { } catch (Throwable t) {

View File

@ -18,7 +18,7 @@ package io.netty.handler.codec.http2;
import io.netty.util.internal.StringUtil; import io.netty.util.internal.StringUtil;
import io.netty.util.internal.UnstableApi; import io.netty.util.internal.UnstableApi;
import static io.netty.util.internal.ObjectUtil.checkNotNull; import static java.util.Objects.requireNonNull;
/** /**
* The default {@link Http2ResetFrame} implementation. * The default {@link Http2ResetFrame} implementation.
@ -34,7 +34,7 @@ public final class DefaultHttp2ResetFrame extends AbstractHttp2StreamFrame imple
* @param error the non-{@code null} reason for reset * @param error the non-{@code null} reason for reset
*/ */
public DefaultHttp2ResetFrame(Http2Error error) { public DefaultHttp2ResetFrame(Http2Error error) {
errorCode = checkNotNull(error, "error").code(); errorCode = requireNonNull(error, "error").code();
} }
/** /**

View File

@ -16,7 +16,8 @@
package io.netty.handler.codec.http2; package io.netty.handler.codec.http2;
import io.netty.util.internal.ObjectUtil; import static java.util.Objects.requireNonNull;
import io.netty.util.internal.StringUtil; import io.netty.util.internal.StringUtil;
import io.netty.util.internal.UnstableApi; import io.netty.util.internal.UnstableApi;
@ -29,7 +30,7 @@ public class DefaultHttp2SettingsFrame implements Http2SettingsFrame {
private final Http2Settings settings; private final Http2Settings settings;
public DefaultHttp2SettingsFrame(Http2Settings settings) { public DefaultHttp2SettingsFrame(Http2Settings settings) {
this.settings = ObjectUtil.checkNotNull(settings, "settings"); this.settings = requireNonNull(settings, "settings");
} }
@Override @Override

View File

@ -32,7 +32,7 @@ import static io.netty.handler.codec.http.HttpHeaderValues.X_DEFLATE;
import static io.netty.handler.codec.http.HttpHeaderValues.X_GZIP; import static io.netty.handler.codec.http.HttpHeaderValues.X_GZIP;
import static io.netty.handler.codec.http2.Http2Error.INTERNAL_ERROR; import static io.netty.handler.codec.http2.Http2Error.INTERNAL_ERROR;
import static io.netty.handler.codec.http2.Http2Exception.streamError; import static io.netty.handler.codec.http2.Http2Exception.streamError;
import static io.netty.util.internal.ObjectUtil.checkNotNull; import static java.util.Objects.requireNonNull;
/** /**
* A HTTP2 frame listener that will decompress data frames according to the {@code content-encoding} header for each * A HTTP2 frame listener that will decompress data frames according to the {@code content-encoding} header for each
@ -286,7 +286,7 @@ public class DelegatingDecompressorFrameListener extends Http2FrameListenerDecor
private final Http2LocalFlowController flowController; private final Http2LocalFlowController flowController;
ConsumedBytesConverter(Http2LocalFlowController flowController) { ConsumedBytesConverter(Http2LocalFlowController flowController) {
this.flowController = checkNotNull(flowController, "flowController"); this.flowController = requireNonNull(flowController, "flowController");
} }
@Override @Override

View File

@ -31,7 +31,7 @@
*/ */
package io.netty.handler.codec.http2; package io.netty.handler.codec.http2;
import static io.netty.util.internal.ObjectUtil.checkNotNull; import static java.util.Objects.requireNonNull;
class HpackHeaderField { class HpackHeaderField {
@ -49,8 +49,8 @@ class HpackHeaderField {
// This constructor can only be used if name and value are ISO-8859-1 encoded. // This constructor can only be used if name and value are ISO-8859-1 encoded.
HpackHeaderField(CharSequence name, CharSequence value) { HpackHeaderField(CharSequence name, CharSequence value) {
this.name = checkNotNull(name, "name"); this.name = requireNonNull(name, "name");
this.value = checkNotNull(value, "value"); this.value = requireNonNull(value, "value");
} }
final int size() { final int size() {

View File

@ -31,10 +31,11 @@
*/ */
package io.netty.handler.codec.http2; package io.netty.handler.codec.http2;
import static java.util.Objects.requireNonNull;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.util.AsciiString; import io.netty.util.AsciiString;
import io.netty.util.ByteProcessor; import io.netty.util.ByteProcessor;
import io.netty.util.internal.ObjectUtil;
import io.netty.util.internal.PlatformDependent; import io.netty.util.internal.PlatformDependent;
final class HpackHuffmanEncoder { final class HpackHuffmanEncoder {
@ -66,7 +67,7 @@ final class HpackHuffmanEncoder {
* @param data the string literal to be Huffman encoded * @param data the string literal to be Huffman encoded
*/ */
public void encode(ByteBuf out, CharSequence data) { public void encode(ByteBuf out, CharSequence data) {
ObjectUtil.checkNotNull(out, "out"); requireNonNull(out, "out");
if (data instanceof AsciiString) { if (data instanceof AsciiString) {
AsciiString string = (AsciiString) data; AsciiString string = (AsciiString) data;
try { try {

View File

@ -34,7 +34,7 @@ import static io.netty.handler.codec.http2.Http2CodecUtil.HTTP_UPGRADE_SETTINGS_
import static io.netty.handler.codec.http2.Http2CodecUtil.SETTING_ENTRY_LENGTH; import static io.netty.handler.codec.http2.Http2CodecUtil.SETTING_ENTRY_LENGTH;
import static io.netty.util.CharsetUtil.UTF_8; import static io.netty.util.CharsetUtil.UTF_8;
import static io.netty.util.ReferenceCountUtil.release; import static io.netty.util.ReferenceCountUtil.release;
import static io.netty.util.internal.ObjectUtil.checkNotNull; import static java.util.Objects.requireNonNull;
/** /**
* Client-side cleartext upgrade codec from HTTP to HTTP/2. * Client-side cleartext upgrade codec from HTTP to HTTP/2.
@ -80,8 +80,8 @@ public class Http2ClientUpgradeCodec implements HttpClientUpgradeHandler.Upgrade
private Http2ClientUpgradeCodec(String handlerName, Http2ConnectionHandler connectionHandler, ChannelHandler private Http2ClientUpgradeCodec(String handlerName, Http2ConnectionHandler connectionHandler, ChannelHandler
upgradeToHandler) { upgradeToHandler) {
this.handlerName = handlerName; this.handlerName = handlerName;
this.connectionHandler = checkNotNull(connectionHandler, "connectionHandler"); this.connectionHandler = requireNonNull(connectionHandler, "connectionHandler");
this.upgradeToHandler = checkNotNull(upgradeToHandler, "upgradeToHandler"); this.upgradeToHandler = requireNonNull(upgradeToHandler, "upgradeToHandler");
} }
@Override @Override

View File

@ -49,8 +49,8 @@ import static io.netty.handler.codec.http2.Http2Exception.isStreamError;
import static io.netty.handler.codec.http2.Http2FrameTypes.SETTINGS; import static io.netty.handler.codec.http2.Http2FrameTypes.SETTINGS;
import static io.netty.handler.codec.http2.Http2Stream.State.IDLE; import static io.netty.handler.codec.http2.Http2Stream.State.IDLE;
import static io.netty.util.CharsetUtil.UTF_8; import static io.netty.util.CharsetUtil.UTF_8;
import static io.netty.util.internal.ObjectUtil.checkNotNull;
import static java.lang.Math.min; import static java.lang.Math.min;
import static java.util.Objects.requireNonNull;
import static java.util.concurrent.TimeUnit.MILLISECONDS; import static java.util.concurrent.TimeUnit.MILLISECONDS;
/** /**
@ -82,9 +82,9 @@ public class Http2ConnectionHandler extends ByteToMessageDecoder implements Http
protected Http2ConnectionHandler(Http2ConnectionDecoder decoder, Http2ConnectionEncoder encoder, protected Http2ConnectionHandler(Http2ConnectionDecoder decoder, Http2ConnectionEncoder encoder,
Http2Settings initialSettings) { Http2Settings initialSettings) {
this.initialSettings = checkNotNull(initialSettings, "initialSettings"); this.initialSettings = requireNonNull(initialSettings, "initialSettings");
this.decoder = checkNotNull(decoder, "decoder"); this.decoder = requireNonNull(decoder, "decoder");
this.encoder = checkNotNull(encoder, "encoder"); this.encoder = requireNonNull(encoder, "encoder");
if (encoder.connection() != decoder.connection()) { if (encoder.connection() != decoder.connection()) {
throw new IllegalArgumentException("Encoder and Decoder do not share the same connection object"); throw new IllegalArgumentException("Encoder and Decoder do not share the same connection object");
} }
@ -92,7 +92,7 @@ public class Http2ConnectionHandler extends ByteToMessageDecoder implements Http
Http2ConnectionHandler(boolean server, Http2FrameWriter frameWriter, Http2FrameLogger frameLogger, Http2ConnectionHandler(boolean server, Http2FrameWriter frameWriter, Http2FrameLogger frameLogger,
Http2Settings initialSettings) { Http2Settings initialSettings) {
this.initialSettings = checkNotNull(initialSettings, "initialSettings"); this.initialSettings = requireNonNull(initialSettings, "initialSettings");
Http2Connection connection = new DefaultHttp2Connection(server); Http2Connection connection = new DefaultHttp2Connection(server);

View File

@ -22,7 +22,7 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import static io.netty.handler.codec.http2.Http2CodecUtil.CONNECTION_STREAM_ID; import static io.netty.handler.codec.http2.Http2CodecUtil.CONNECTION_STREAM_ID;
import static io.netty.util.internal.ObjectUtil.checkNotNull; import static java.util.Objects.requireNonNull;
/** /**
* Exception thrown when an HTTP/2 error was encountered. * Exception thrown when an HTTP/2 error was encountered.
@ -38,8 +38,8 @@ public class Http2Exception extends Exception {
} }
public Http2Exception(Http2Error error, ShutdownHint shutdownHint) { public Http2Exception(Http2Error error, ShutdownHint shutdownHint) {
this.error = checkNotNull(error, "error"); this.error = requireNonNull(error, "error");
this.shutdownHint = checkNotNull(shutdownHint, "shutdownHint"); this.shutdownHint = requireNonNull(shutdownHint, "shutdownHint");
} }
public Http2Exception(Http2Error error, String message) { public Http2Exception(Http2Error error, String message) {
@ -48,8 +48,8 @@ public class Http2Exception extends Exception {
public Http2Exception(Http2Error error, String message, ShutdownHint shutdownHint) { public Http2Exception(Http2Error error, String message, ShutdownHint shutdownHint) {
super(message); super(message);
this.error = checkNotNull(error, "error"); this.error = requireNonNull(error, "error");
this.shutdownHint = checkNotNull(shutdownHint, "shutdownHint"); this.shutdownHint = requireNonNull(shutdownHint, "shutdownHint");
} }
public Http2Exception(Http2Error error, String message, Throwable cause) { public Http2Exception(Http2Error error, String message, Throwable cause) {
@ -58,8 +58,8 @@ public class Http2Exception extends Exception {
public Http2Exception(Http2Error error, String message, Throwable cause, ShutdownHint shutdownHint) { public Http2Exception(Http2Error error, String message, Throwable cause, ShutdownHint shutdownHint) {
super(message, cause); super(message, cause);
this.error = checkNotNull(error, "error"); this.error = requireNonNull(error, "error");
this.shutdownHint = checkNotNull(shutdownHint, "shutdownHint"); this.shutdownHint = requireNonNull(shutdownHint, "shutdownHint");
} }
public Http2Error error() { public Http2Error error() {

View File

@ -18,7 +18,7 @@ package io.netty.handler.codec.http2;
import io.netty.util.internal.UnstableApi; import io.netty.util.internal.UnstableApi;
import static io.netty.util.internal.ObjectUtil.checkNotNull; import static java.util.Objects.requireNonNull;
/** /**
* Builder for the {@link Http2FrameCodec}. * Builder for the {@link Http2FrameCodec}.
@ -49,7 +49,7 @@ public class Http2FrameCodecBuilder extends
// For testing only. // For testing only.
Http2FrameCodecBuilder frameWriter(Http2FrameWriter frameWriter) { Http2FrameCodecBuilder frameWriter(Http2FrameWriter frameWriter) {
this.frameWriter = checkNotNull(frameWriter, "frameWriter"); this.frameWriter = requireNonNull(frameWriter, "frameWriter");
return this; return this;
} }

Some files were not shown because too many files have changed in this diff Show More