Uniform null pointer check. (#9840)

Motivation:
Uniform null pointer check.

Modifications:

Use ObjectUtil.checkNonNull(...)

Result:
Less code, same result.
This commit is contained in:
时无两丶 2019-12-09 16:47:35 +08:00 committed by Norman Maurer
parent e875e59a9b
commit 0cde4d9cb4
216 changed files with 676 additions and 1419 deletions

View File

@ -21,6 +21,7 @@ import io.netty.util.CharsetUtil;
import io.netty.util.IllegalReferenceCountException;
import io.netty.util.ResourceLeakDetector;
import io.netty.util.ResourceLeakDetectorFactory;
import io.netty.util.internal.ObjectUtil;
import io.netty.util.internal.PlatformDependent;
import io.netty.util.internal.StringUtil;
import io.netty.util.internal.SystemPropertyUtil;
@ -339,9 +340,7 @@ public abstract class AbstractByteBuf extends ByteBuf {
if (endianness == order()) {
return this;
}
if (endianness == null) {
throw new NullPointerException("endianness");
}
ObjectUtil.checkNotNull(endianness, "endianness");
return newSwappedByteBuf();
}
@ -649,9 +648,7 @@ public abstract class AbstractByteBuf extends ByteBuf {
@Override
public ByteBuf setBytes(int index, ByteBuf src, int length) {
checkIndex(index, length);
if (src == null) {
throw new NullPointerException("src");
}
ObjectUtil.checkNotNull(src, "src");
if (checkBounds) {
checkReadableBounds(src, length);
}

View File

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

View File

@ -16,6 +16,7 @@
package io.netty.buffer;
import io.netty.util.CharsetUtil;
import io.netty.util.internal.ObjectUtil;
import java.io.DataOutput;
import java.io.DataOutputStream;
@ -45,10 +46,7 @@ public class ByteBufOutputStream extends OutputStream implements DataOutput {
* Creates a new stream which writes data to the specified {@code buffer}.
*/
public ByteBufOutputStream(ByteBuf buffer) {
if (buffer == null) {
throw new NullPointerException("buffer");
}
this.buffer = buffer;
this.buffer = ObjectUtil.checkNotNull(buffer, "buffer");
startIndex = buffer.writerIndex();
}

View File

@ -19,6 +19,7 @@ import io.netty.util.ByteProcessor;
import io.netty.util.IllegalReferenceCountException;
import io.netty.util.ReferenceCountUtil;
import io.netty.util.internal.EmptyArrays;
import io.netty.util.internal.ObjectUtil;
import io.netty.util.internal.RecyclableArrayList;
import java.io.IOException;
@ -61,14 +62,13 @@ public class CompositeByteBuf extends AbstractReferenceCountedByteBuf implements
private CompositeByteBuf(ByteBufAllocator alloc, boolean direct, int maxNumComponents, int initSize) {
super(AbstractByteBufAllocator.DEFAULT_MAX_CAPACITY);
if (alloc == null) {
throw new NullPointerException("alloc");
}
this.alloc = ObjectUtil.checkNotNull(alloc, "alloc");
if (maxNumComponents < 1) {
throw new IllegalArgumentException(
"maxNumComponents: " + maxNumComponents + " (expected: >= 1)");
}
this.alloc = alloc;
this.direct = direct;
this.maxNumComponents = maxNumComponents;
components = newCompArray(initSize, maxNumComponents);

View File

@ -16,6 +16,7 @@
package io.netty.buffer;
import io.netty.util.IllegalReferenceCountException;
import io.netty.util.internal.ObjectUtil;
import io.netty.util.internal.StringUtil;
/**
@ -27,10 +28,7 @@ public class DefaultByteBufHolder implements ByteBufHolder {
private final ByteBuf data;
public DefaultByteBufHolder(ByteBuf data) {
if (data == null) {
throw new NullPointerException("data");
}
this.data = data;
this.data = ObjectUtil.checkNotNull(data, "data");
}
@Override

View File

@ -20,6 +20,7 @@ import static io.netty.util.internal.ObjectUtil.checkPositiveOrZero;
import io.netty.util.ByteProcessor;
import io.netty.util.internal.EmptyArrays;
import io.netty.util.internal.ObjectUtil;
import io.netty.util.internal.PlatformDependent;
import io.netty.util.internal.StringUtil;
@ -64,11 +65,7 @@ public final class EmptyByteBuf extends ByteBuf {
}
private EmptyByteBuf(ByteBufAllocator alloc, ByteOrder order) {
if (alloc == null) {
throw new NullPointerException("alloc");
}
this.alloc = alloc;
this.alloc = ObjectUtil.checkNotNull(alloc, "alloc");
this.order = order;
str = StringUtil.simpleClassName(this) + (order == ByteOrder.BIG_ENDIAN? "BE" : "LE");
}
@ -120,10 +117,7 @@ public final class EmptyByteBuf extends ByteBuf {
@Override
public ByteBuf order(ByteOrder endianness) {
if (endianness == null) {
throw new NullPointerException("endianness");
}
if (endianness == order()) {
if (ObjectUtil.checkNotNull(endianness, "endianness") == order()) {
return this;
}

View File

@ -16,6 +16,7 @@
package io.netty.buffer;
import io.netty.util.internal.ObjectUtil;
import io.netty.util.internal.PlatformDependent;
import java.nio.ByteBuffer;
@ -62,9 +63,7 @@ final class ReadOnlyUnsafeDirectByteBuf extends ReadOnlyByteBufferBuf {
@Override
public ByteBuf getBytes(int index, ByteBuf dst, int dstIndex, int length) {
checkIndex(index, length);
if (dst == null) {
throw new NullPointerException("dst");
}
ObjectUtil.checkNotNull(dst, "dst");
if (dstIndex < 0 || dstIndex > dst.capacity() - length) {
throw new IndexOutOfBoundsException("dstIndex: " + dstIndex);
}
@ -82,9 +81,7 @@ final class ReadOnlyUnsafeDirectByteBuf extends ReadOnlyByteBufferBuf {
@Override
public ByteBuf getBytes(int index, byte[] dst, int dstIndex, int length) {
checkIndex(index, length);
if (dst == null) {
throw new NullPointerException("dst");
}
ObjectUtil.checkNotNull(dst, "dst");
if (dstIndex < 0 || dstIndex > dst.length - length) {
throw new IndexOutOfBoundsException(String.format(
"dstIndex: %d, length: %d (expected: range(0, %d))", dstIndex, length, dst.length));

View File

@ -16,6 +16,7 @@
package io.netty.buffer;
import io.netty.util.ByteProcessor;
import io.netty.util.internal.ObjectUtil;
import java.io.IOException;
import java.io.InputStream;
@ -40,10 +41,7 @@ public class SwappedByteBuf extends ByteBuf {
private final ByteOrder order;
public SwappedByteBuf(ByteBuf buf) {
if (buf == null) {
throw new NullPointerException("buf");
}
this.buf = buf;
this.buf = ObjectUtil.checkNotNull(buf, "buf");
if (buf.order() == ByteOrder.BIG_ENDIAN) {
order = ByteOrder.LITTLE_ENDIAN;
} else {
@ -58,10 +56,7 @@ public class SwappedByteBuf extends ByteBuf {
@Override
public ByteBuf order(ByteOrder endianness) {
if (endianness == null) {
throw new NullPointerException("endianness");
}
if (endianness == order) {
if (ObjectUtil.checkNotNull(endianness, "endianness") == order) {
return this;
}
return buf;

View File

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

View File

@ -15,8 +15,7 @@
*/
package io.netty.buffer;
import static io.netty.util.internal.ObjectUtil.checkPositiveOrZero;
import io.netty.util.internal.ObjectUtil;
import io.netty.util.internal.PlatformDependent;
import java.io.IOException;
@ -29,6 +28,8 @@ import java.nio.channels.FileChannel;
import java.nio.channels.GatheringByteChannel;
import java.nio.channels.ScatteringByteChannel;
import static io.netty.util.internal.ObjectUtil.checkPositiveOrZero;
/**
* A NIO {@link ByteBuffer} based buffer. It is recommended to use
* {@link UnpooledByteBufAllocator#directBuffer(int, int)}, {@link Unpooled#directBuffer(int)} and
@ -51,9 +52,7 @@ public class UnpooledDirectByteBuf extends AbstractReferenceCountedByteBuf {
*/
public UnpooledDirectByteBuf(ByteBufAllocator alloc, int initialCapacity, int maxCapacity) {
super(maxCapacity);
if (alloc == null) {
throw new NullPointerException("alloc");
}
ObjectUtil.checkNotNull(alloc, "alloc");
checkPositiveOrZero(initialCapacity, "initialCapacity");
checkPositiveOrZero(maxCapacity, "maxCapacity");
if (initialCapacity > maxCapacity) {
@ -77,12 +76,8 @@ public class UnpooledDirectByteBuf extends AbstractReferenceCountedByteBuf {
UnpooledDirectByteBuf(ByteBufAllocator alloc, ByteBuffer initialBuffer,
int maxCapacity, boolean doFree, boolean slice) {
super(maxCapacity);
if (alloc == null) {
throw new NullPointerException("alloc");
}
if (initialBuffer == null) {
throw new NullPointerException("initialBuffer");
}
ObjectUtil.checkNotNull(alloc, "alloc");
ObjectUtil.checkNotNull(initialBuffer, "initialBuffer");
if (!initialBuffer.isDirect()) {
throw new IllegalArgumentException("initialBuffer is not a direct buffer.");
}

View File

@ -50,14 +50,12 @@ public class UnpooledHeapByteBuf extends AbstractReferenceCountedByteBuf {
public UnpooledHeapByteBuf(ByteBufAllocator alloc, int initialCapacity, int maxCapacity) {
super(maxCapacity);
checkNotNull(alloc, "alloc");
if (initialCapacity > maxCapacity) {
throw new IllegalArgumentException(String.format(
"initialCapacity(%d) > maxCapacity(%d)", initialCapacity, maxCapacity));
}
this.alloc = alloc;
this.alloc = checkNotNull(alloc, "alloc");
setArray(allocateArray(initialCapacity));
setIndex(0, 0);
}
@ -73,7 +71,6 @@ public class UnpooledHeapByteBuf extends AbstractReferenceCountedByteBuf {
checkNotNull(alloc, "alloc");
checkNotNull(initialArray, "initialArray");
if (initialArray.length > maxCapacity) {
throw new IllegalArgumentException(String.format(
"initialCapacity(%d) > maxCapacity(%d)", initialArray.length, maxCapacity));

View File

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

View File

@ -17,6 +17,7 @@
package io.netty.buffer;
import io.netty.util.ByteProcessor;
import io.netty.util.internal.ObjectUtil;
import io.netty.util.internal.StringUtil;
import java.io.IOException;
@ -41,10 +42,7 @@ class WrappedByteBuf extends ByteBuf {
protected final ByteBuf buf;
protected WrappedByteBuf(ByteBuf buf) {
if (buf == null) {
throw new NullPointerException("buf");
}
this.buf = buf;
this.buf = ObjectUtil.checkNotNull(buf, "buf");
}
@Override

View File

@ -16,6 +16,7 @@
package io.netty.buffer;
import io.netty.util.ReferenceCountUtil;
import io.netty.util.internal.ObjectUtil;
import io.netty.util.internal.PlatformDependent;
import org.junit.Assume;
import org.junit.Test;
@ -57,10 +58,7 @@ public abstract class AbstractCompositeByteBufTest extends AbstractByteBufTest {
private final ByteOrder order;
protected AbstractCompositeByteBufTest(ByteOrder order) {
if (order == null) {
throw new NullPointerException("order");
}
this.order = order;
this.order = ObjectUtil.checkNotNull(order, "order");
}
@Override

View File

@ -24,6 +24,7 @@ import io.netty.util.NetUtil;
import io.netty.util.ResourceLeakDetector;
import io.netty.util.ResourceLeakDetectorFactory;
import io.netty.util.ResourceLeakTracker;
import io.netty.util.internal.ObjectUtil;
import java.util.ArrayList;
import java.util.Collections;
@ -76,9 +77,7 @@ public final class HAProxyMessage extends AbstractReferenceCounted {
String sourceAddress, String destinationAddress, int sourcePort, int destinationPort,
List<HAProxyTLV> tlvs) {
if (proxiedProtocol == null) {
throw new NullPointerException("proxiedProtocol");
}
ObjectUtil.checkNotNull(proxiedProtocol, "proxiedProtocol");
AddressFamily addrFamily = proxiedProtocol.addressFamily();
checkAddress(sourceAddress, addrFamily);
@ -106,9 +105,7 @@ public final class HAProxyMessage extends AbstractReferenceCounted {
* @throws HAProxyProtocolException if any portion of the header is invalid
*/
static HAProxyMessage decodeHeader(ByteBuf header) {
if (header == null) {
throw new NullPointerException("header");
}
ObjectUtil.checkNotNull(header, "header");
if (header.readableBytes() < 16) {
throw new HAProxyProtocolException(
@ -401,9 +398,7 @@ public final class HAProxyMessage extends AbstractReferenceCounted {
* @throws HAProxyProtocolException if the address is invalid
*/
private static void checkAddress(String address, AddressFamily addrFamily) {
if (addrFamily == null) {
throw new NullPointerException("addrFamily");
}
ObjectUtil.checkNotNull(addrFamily, "addrFamily");
switch (addrFamily) {
case AF_UNSPEC:
@ -415,9 +410,7 @@ public final class HAProxyMessage extends AbstractReferenceCounted {
return;
}
if (address == null) {
throw new NullPointerException("address");
}
ObjectUtil.checkNotNull(address, "address");
switch (addrFamily) {
case AF_IPv4:

View File

@ -85,9 +85,7 @@ public class HAProxyTLV extends DefaultByteBufHolder {
*/
HAProxyTLV(final Type type, final byte typeByteValue, final ByteBuf content) {
super(content);
checkNotNull(type, "type");
this.type = type;
this.type = checkNotNull(type, "type");
this.typeByteValue = typeByteValue;
}

View File

@ -15,6 +15,8 @@
*/
package io.netty.handler.codec.http;
import io.netty.util.internal.ObjectUtil;
import java.util.Collections;
import java.util.Set;
import java.util.TreeSet;
@ -131,9 +133,7 @@ public class DefaultCookie extends io.netty.handler.codec.http.cookie.DefaultCoo
@Override
@Deprecated
public void setPorts(int... ports) {
if (ports == null) {
throw new NullPointerException("ports");
}
ObjectUtil.checkNotNull(ports, "ports");
int[] portsCopy = ports.clone();
if (portsCopy.length == 0) {

View File

@ -16,6 +16,7 @@
package io.netty.handler.codec.http;
import io.netty.buffer.ByteBuf;
import io.netty.util.internal.ObjectUtil;
import io.netty.util.internal.StringUtil;
/**
@ -29,10 +30,7 @@ public class DefaultHttpContent extends DefaultHttpObject implements HttpContent
* Creates a new instance with the specified chunk content.
*/
public DefaultHttpContent(ByteBuf content) {
if (content == null) {
throw new NullPointerException("content");
}
this.content = content;
this.content = ObjectUtil.checkNotNull(content, "content");
}
@Override

View File

@ -15,6 +15,8 @@
*/
package io.netty.handler.codec.http;
import io.netty.util.internal.ObjectUtil;
import static io.netty.util.internal.ObjectUtil.checkNotNull;
/**
@ -89,10 +91,7 @@ public abstract class DefaultHttpMessage extends DefaultHttpObject implements Ht
@Override
public HttpMessage setProtocolVersion(HttpVersion version) {
if (version == null) {
throw new NullPointerException("version");
}
this.version = version;
this.version = ObjectUtil.checkNotNull(version, "version");
return this;
}
}

View File

@ -16,6 +16,7 @@
package io.netty.handler.codec.http;
import io.netty.handler.codec.DecoderResult;
import io.netty.util.internal.ObjectUtil;
public class DefaultHttpObject implements HttpObject {
@ -39,10 +40,7 @@ public class DefaultHttpObject implements HttpObject {
@Override
public void setDecoderResult(DecoderResult decoderResult) {
if (decoderResult == null) {
throw new NullPointerException("decoderResult");
}
this.decoderResult = decoderResult;
this.decoderResult = ObjectUtil.checkNotNull(decoderResult, "decoderResult");
}
@Override

View File

@ -15,6 +15,8 @@
*/
package io.netty.handler.codec.http;
import io.netty.util.internal.ObjectUtil;
import static io.netty.util.internal.ObjectUtil.checkNotNull;
/**
@ -88,19 +90,13 @@ public class DefaultHttpRequest extends DefaultHttpMessage implements HttpReques
@Override
public HttpRequest setMethod(HttpMethod method) {
if (method == null) {
throw new NullPointerException("method");
}
this.method = method;
this.method = ObjectUtil.checkNotNull(method, "method");
return this;
}
@Override
public HttpRequest setUri(String uri) {
if (uri == null) {
throw new NullPointerException("uri");
}
this.uri = uri;
this.uri = ObjectUtil.checkNotNull(uri, "uri");
return this;
}

View File

@ -15,6 +15,8 @@
*/
package io.netty.handler.codec.http;
import io.netty.util.internal.ObjectUtil;
import static io.netty.util.internal.ObjectUtil.checkNotNull;
/**
@ -88,10 +90,7 @@ public class DefaultHttpResponse extends DefaultHttpMessage implements HttpRespo
@Override
public HttpResponse setStatus(HttpResponseStatus status) {
if (status == null) {
throw new NullPointerException("status");
}
this.status = status;
this.status = ObjectUtil.checkNotNull(status, "status");
return this;
}

View File

@ -18,6 +18,7 @@ import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelOutboundHandler;
import io.netty.channel.ChannelPromise;
import io.netty.util.AsciiString;
import io.netty.util.internal.ObjectUtil;
import java.net.SocketAddress;
import java.util.Collection;
@ -115,14 +116,8 @@ public class HttpClientUpgradeHandler extends HttpObjectAggregator implements Ch
public HttpClientUpgradeHandler(SourceCodec sourceCodec, UpgradeCodec upgradeCodec,
int maxContentLength) {
super(maxContentLength);
if (sourceCodec == null) {
throw new NullPointerException("sourceCodec");
}
if (upgradeCodec == null) {
throw new NullPointerException("upgradeCodec");
}
this.sourceCodec = sourceCodec;
this.upgradeCodec = upgradeCodec;
this.sourceCodec = ObjectUtil.checkNotNull(sourceCodec, "sourceCodec");
this.upgradeCodec = ObjectUtil.checkNotNull(upgradeCodec, "upgradeCodec");
}
@Override

View File

@ -22,6 +22,7 @@ import io.netty.channel.embedded.EmbeddedChannel;
import io.netty.handler.codec.DecoderResult;
import io.netty.handler.codec.MessageToMessageCodec;
import io.netty.util.ReferenceCountUtil;
import io.netty.util.internal.ObjectUtil;
import io.netty.util.internal.StringUtil;
import java.util.ArrayDeque;
@ -362,15 +363,8 @@ public abstract class HttpContentEncoder extends MessageToMessageCodec<HttpReque
private final EmbeddedChannel contentEncoder;
public Result(String targetContentEncoding, EmbeddedChannel contentEncoder) {
if (targetContentEncoding == null) {
throw new NullPointerException("targetContentEncoding");
}
if (contentEncoder == null) {
throw new NullPointerException("contentEncoder");
}
this.targetContentEncoding = targetContentEncoding;
this.contentEncoder = contentEncoder;
this.targetContentEncoding = ObjectUtil.checkNotNull(targetContentEncoding, "targetContentEncoding");
this.contentEncoder = ObjectUtil.checkNotNull(contentEncoder, "contentEncoder");
}
public String targetContentEncoding() {

View File

@ -22,6 +22,7 @@ import io.netty.handler.codec.Headers;
import io.netty.handler.codec.HeadersUtils;
import io.netty.util.AsciiString;
import io.netty.util.CharsetUtil;
import io.netty.util.internal.ObjectUtil;
import java.text.ParseException;
import java.util.Calendar;
@ -1412,9 +1413,7 @@ public abstract class HttpHeaders implements Iterable<Map.Entry<String, String>>
* @return {@code this}
*/
public HttpHeaders add(HttpHeaders headers) {
if (headers == null) {
throw new NullPointerException("headers");
}
ObjectUtil.checkNotNull(headers, "headers");
for (Map.Entry<String, String> e: headers) {
add(e.getKey(), e.getValue());
}

View File

@ -19,6 +19,7 @@ import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import io.netty.util.AsciiString;
import io.netty.util.CharsetUtil;
import io.netty.util.internal.ObjectUtil;
import static io.netty.handler.codec.http.HttpConstants.SP;
import static io.netty.util.ByteProcessor.FIND_ASCII_SPACE;
@ -540,10 +541,7 @@ public class HttpResponseStatus implements Comparable<HttpResponseStatus> {
private HttpResponseStatus(int code, String reasonPhrase, boolean bytes) {
checkPositiveOrZero(code, "code");
if (reasonPhrase == null) {
throw new NullPointerException("reasonPhrase");
}
ObjectUtil.checkNotNull(reasonPhrase, "reasonPhrase");
for (int i = 0; i < reasonPhrase.length(); i ++) {
char c = reasonPhrase.charAt(i);

View File

@ -27,6 +27,7 @@ import java.util.List;
import io.netty.util.AsciiString;
import io.netty.util.CharsetUtil;
import io.netty.util.NetUtil;
import io.netty.util.internal.ObjectUtil;
/**
* Utility methods useful in the HTTP context.
@ -448,9 +449,7 @@ public final class HttpUtil {
* @throws NullPointerException in case if {@code contentTypeValue == null}
*/
public static CharSequence getCharsetAsSequence(CharSequence contentTypeValue) {
if (contentTypeValue == null) {
throw new NullPointerException("contentTypeValue");
}
ObjectUtil.checkNotNull(contentTypeValue, "contentTypeValue");
int indexOfCharset = AsciiString.indexOfIgnoreCaseAscii(contentTypeValue, CHARSET_EQUALS, 0);
if (indexOfCharset == AsciiString.INDEX_NOT_FOUND) {
@ -504,9 +503,7 @@ public final class HttpUtil {
* @throws NullPointerException in case if {@code contentTypeValue == null}
*/
public static CharSequence getMimeType(CharSequence contentTypeValue) {
if (contentTypeValue == null) {
throw new NullPointerException("contentTypeValue");
}
ObjectUtil.checkNotNull(contentTypeValue, "contentTypeValue");
int indexOfSemicolon = AsciiString.indexOfIgnoreCaseAscii(contentTypeValue, SEMICOLON, 0);
if (indexOfSemicolon != AsciiString.INDEX_NOT_FOUND) {

View File

@ -19,6 +19,7 @@ import static io.netty.util.internal.ObjectUtil.checkPositiveOrZero;
import io.netty.buffer.ByteBuf;
import io.netty.util.CharsetUtil;
import io.netty.util.internal.ObjectUtil;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -55,9 +56,7 @@ public class HttpVersion implements Comparable<HttpVersion> {
* returned.
*/
public static HttpVersion valueOf(String text) {
if (text == null) {
throw new NullPointerException("text");
}
ObjectUtil.checkNotNull(text, "text");
text = text.trim();
@ -109,9 +108,7 @@ public class HttpVersion implements Comparable<HttpVersion> {
* the {@code "Connection"} header is set to {@code "close"} explicitly.
*/
public HttpVersion(String text, boolean keepAliveDefault) {
if (text == null) {
throw new NullPointerException("text");
}
ObjectUtil.checkNotNull(text, "text");
text = text.trim().toUpperCase();
if (text.isEmpty()) {
@ -151,9 +148,7 @@ public class HttpVersion implements Comparable<HttpVersion> {
private HttpVersion(
String protocolName, int majorVersion, int minorVersion,
boolean keepAliveDefault, boolean bytes) {
if (protocolName == null) {
throw new NullPointerException("protocolName");
}
ObjectUtil.checkNotNull(protocolName, "protocolName");
protocolName = protocolName.trim().toUpperCase();
if (protocolName.isEmpty()) {

View File

@ -18,6 +18,7 @@ package io.netty.handler.codec.http.multipart;
import io.netty.buffer.ByteBuf;
import io.netty.handler.codec.http.HttpConstants;
import io.netty.util.internal.EmptyArrays;
import io.netty.util.internal.ObjectUtil;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;
@ -99,9 +100,7 @@ public abstract class AbstractDiskHttpData extends AbstractHttpData {
@Override
public void setContent(ByteBuf buffer) throws IOException {
if (buffer == null) {
throw new NullPointerException("buffer");
}
ObjectUtil.checkNotNull(buffer, "buffer");
try {
size = buffer.readableBytes();
checkSize(size);
@ -190,9 +189,7 @@ public abstract class AbstractDiskHttpData extends AbstractHttpData {
fileChannel = null;
setCompleted();
} else {
if (buffer == null) {
throw new NullPointerException("buffer");
}
ObjectUtil.checkNotNull(buffer, "buffer");
}
}
@ -210,9 +207,7 @@ public abstract class AbstractDiskHttpData extends AbstractHttpData {
@Override
public void setContent(InputStream inputStream) throws IOException {
if (inputStream == null) {
throw new NullPointerException("inputStream");
}
ObjectUtil.checkNotNull(inputStream, "inputStream");
if (file != null) {
delete();
}
@ -341,9 +336,7 @@ public abstract class AbstractDiskHttpData extends AbstractHttpData {
@Override
public boolean renameTo(File dest) throws IOException {
if (dest == null) {
throw new NullPointerException("dest");
}
ObjectUtil.checkNotNull(dest, "dest");
if (file == null) {
throw new IOException("No file defined so cannot be renamed");
}

View File

@ -19,6 +19,7 @@ import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelException;
import io.netty.handler.codec.http.HttpConstants;
import io.netty.util.AbstractReferenceCounted;
import io.netty.util.internal.ObjectUtil;
import java.io.IOException;
import java.nio.charset.Charset;
@ -40,9 +41,7 @@ public abstract class AbstractHttpData extends AbstractReferenceCounted implemen
private long maxSize = DefaultHttpDataFactory.MAXSIZE;
protected AbstractHttpData(String name, Charset charset, long size) {
if (name == null) {
throw new NullPointerException("name");
}
ObjectUtil.checkNotNull(name, "name");
name = REPLACE_PATTERN.matcher(name).replaceAll(" ");
name = STRIP_PATTERN.matcher(name).replaceAll("");
@ -96,10 +95,7 @@ public abstract class AbstractHttpData extends AbstractReferenceCounted implemen
@Override
public void setCharset(Charset charset) {
if (charset == null) {
throw new NullPointerException("charset");
}
this.charset = charset;
this.charset = ObjectUtil.checkNotNull(charset, "charset");
}
@Override

View File

@ -18,6 +18,7 @@ package io.netty.handler.codec.http.multipart;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.CompositeByteBuf;
import io.netty.handler.codec.http.HttpConstants;
import io.netty.util.internal.ObjectUtil;
import java.io.File;
import java.io.IOException;
@ -46,9 +47,7 @@ public abstract class AbstractMemoryHttpData extends AbstractHttpData {
@Override
public void setContent(ByteBuf buffer) throws IOException {
if (buffer == null) {
throw new NullPointerException("buffer");
}
ObjectUtil.checkNotNull(buffer, "buffer");
long localsize = buffer.readableBytes();
checkSize(localsize);
if (definedSize > 0 && definedSize < localsize) {
@ -65,9 +64,8 @@ public abstract class AbstractMemoryHttpData extends AbstractHttpData {
@Override
public void setContent(InputStream inputStream) throws IOException {
if (inputStream == null) {
throw new NullPointerException("inputStream");
}
ObjectUtil.checkNotNull(inputStream, "inputStream");
ByteBuf buffer = buffer();
byte[] bytes = new byte[4096 * 4];
int read = inputStream.read(bytes);
@ -114,17 +112,14 @@ public abstract class AbstractMemoryHttpData extends AbstractHttpData {
if (last) {
setCompleted();
} else {
if (buffer == null) {
throw new NullPointerException("buffer");
}
ObjectUtil.checkNotNull(buffer, "buffer");
}
}
@Override
public void setContent(File file) throws IOException {
if (file == null) {
throw new NullPointerException("file");
}
ObjectUtil.checkNotNull(file, "file");
long newsize = file.length();
if (newsize > Integer.MAX_VALUE) {
throw new IllegalArgumentException("File too big to be loaded in memory");
@ -220,9 +215,7 @@ public abstract class AbstractMemoryHttpData extends AbstractHttpData {
@Override
public boolean renameTo(File dest) throws IOException {
if (dest == null) {
throw new NullPointerException("dest");
}
ObjectUtil.checkNotNull(dest, "dest");
if (byteBuf == null) {
// empty file
if (!dest.createNewFile()) {

View File

@ -18,6 +18,7 @@ package io.netty.handler.codec.http.multipart;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelException;
import io.netty.handler.codec.http.HttpConstants;
import io.netty.util.internal.ObjectUtil;
import java.io.IOException;
import java.nio.charset.Charset;
@ -77,9 +78,7 @@ public class DiskAttribute extends AbstractDiskHttpData implements Attribute {
@Override
public void setValue(String value) throws IOException {
if (value == null) {
throw new NullPointerException("value");
}
ObjectUtil.checkNotNull(value, "value");
byte [] bytes = value.getBytes(getCharset());
checkSize(bytes.length);
ByteBuf buffer = wrappedBuffer(bytes);

View File

@ -19,6 +19,7 @@ import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelException;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpHeaderValues;
import io.netty.util.internal.ObjectUtil;
import java.io.File;
import java.io.IOException;
@ -62,10 +63,7 @@ public class DiskFileUpload extends AbstractDiskHttpData implements FileUpload {
@Override
public void setFilename(String filename) {
if (filename == null) {
throw new NullPointerException("filename");
}
this.filename = filename;
this.filename = ObjectUtil.checkNotNull(filename, "filename");
}
@Override
@ -93,10 +91,7 @@ public class DiskFileUpload extends AbstractDiskHttpData implements FileUpload {
@Override
public void setContentType(String contentType) {
if (contentType == null) {
throw new NullPointerException("contentType");
}
this.contentType = contentType;
this.contentType = ObjectUtil.checkNotNull(contentType, "contentType");
}
@Override

View File

@ -21,6 +21,7 @@ import io.netty.handler.codec.http.HttpContent;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpHeaderValues;
import io.netty.handler.codec.http.HttpRequest;
import io.netty.util.internal.ObjectUtil;
import io.netty.util.internal.StringUtil;
import java.nio.charset.Charset;
@ -83,15 +84,10 @@ public class HttpPostRequestDecoder implements InterfaceHttpPostRequestDecoder {
* errors
*/
public HttpPostRequestDecoder(HttpDataFactory factory, HttpRequest request, Charset charset) {
if (factory == null) {
throw new NullPointerException("factory");
}
if (request == null) {
throw new NullPointerException("request");
}
if (charset == null) {
throw new NullPointerException("charset");
}
ObjectUtil.checkNotNull(factory, "factory");
ObjectUtil.checkNotNull(request, "request");
ObjectUtil.checkNotNull(charset, "charset");
// Fill default values
if (isMultipart(request)) {
decoder = new HttpPostMultipartRequestDecoder(factory, request, charset);

View File

@ -34,6 +34,7 @@ import io.netty.handler.codec.http.HttpUtil;
import io.netty.handler.codec.http.HttpVersion;
import io.netty.handler.codec.http.LastHttpContent;
import io.netty.handler.stream.ChunkedInput;
import io.netty.util.internal.ObjectUtil;
import io.netty.util.internal.PlatformDependent;
import io.netty.util.internal.StringUtil;
@ -310,9 +311,7 @@ public class HttpPostRequestEncoder implements ChunkedInput<HttpContent> {
* if the encoding is in error or if the finalize were already done
*/
public void setBodyHttpDatas(List<InterfaceHttpData> datas) throws ErrorDataEncoderException {
if (datas == null) {
throw new NullPointerException("datas");
}
ObjectUtil.checkNotNull(datas, "datas");
globalBodySize = 0;
bodyListDatas.clear();
currentFileUpload = null;

View File

@ -18,6 +18,7 @@ package io.netty.handler.codec.http.multipart;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.util.AbstractReferenceCounted;
import io.netty.util.internal.ObjectUtil;
import java.nio.charset.Charset;
import java.util.ArrayList;
@ -42,27 +43,21 @@ final class InternalAttribute extends AbstractReferenceCounted implements Interf
}
public void addValue(String value) {
if (value == null) {
throw new NullPointerException("value");
}
ObjectUtil.checkNotNull(value, "value");
ByteBuf buf = Unpooled.copiedBuffer(value, charset);
this.value.add(buf);
size += buf.readableBytes();
}
public void addValue(String value, int rank) {
if (value == null) {
throw new NullPointerException("value");
}
ObjectUtil.checkNotNull(value, "value");
ByteBuf buf = Unpooled.copiedBuffer(value, charset);
this.value.add(rank, buf);
size += buf.readableBytes();
}
public void setValue(String value, int rank) {
if (value == null) {
throw new NullPointerException("value");
}
ObjectUtil.checkNotNull(value, "value");
ByteBuf buf = Unpooled.copiedBuffer(value, charset);
ByteBuf old = this.value.set(rank, buf);
if (old != null) {

View File

@ -18,6 +18,7 @@ package io.netty.handler.codec.http.multipart;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelException;
import io.netty.handler.codec.http.HttpConstants;
import io.netty.util.internal.ObjectUtil;
import java.io.IOException;
import java.nio.charset.Charset;
@ -66,9 +67,7 @@ public class MemoryAttribute extends AbstractMemoryHttpData implements Attribute
@Override
public void setValue(String value) throws IOException {
if (value == null) {
throw new NullPointerException("value");
}
ObjectUtil.checkNotNull(value, "value");
byte [] bytes = value.getBytes(getCharset());
checkSize(bytes.length);
ByteBuf buffer = wrappedBuffer(bytes);

View File

@ -19,6 +19,7 @@ import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelException;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpHeaderValues;
import io.netty.util.internal.ObjectUtil;
import java.io.IOException;
import java.nio.charset.Charset;
@ -56,10 +57,7 @@ public class MemoryFileUpload extends AbstractMemoryHttpData implements FileUplo
@Override
public void setFilename(String filename) {
if (filename == null) {
throw new NullPointerException("filename");
}
this.filename = filename;
this.filename = ObjectUtil.checkNotNull(filename, "filename");
}
@Override
@ -87,10 +85,7 @@ public class MemoryFileUpload extends AbstractMemoryHttpData implements FileUplo
@Override
public void setContentType(String contentType) {
if (contentType == null) {
throw new NullPointerException("contentType");
}
this.contentType = contentType;
this.contentType = ObjectUtil.checkNotNull(contentType, "contentType");
}
@Override

View File

@ -35,6 +35,7 @@ import io.netty.handler.codec.http.HttpResponseDecoder;
import io.netty.handler.codec.http.HttpScheme;
import io.netty.util.NetUtil;
import io.netty.util.ReferenceCountUtil;
import io.netty.util.internal.ObjectUtil;
import java.net.URI;
import java.nio.channels.ClosedChannelException;
@ -231,9 +232,7 @@ public abstract class WebSocketClientHandshaker {
* Channel
*/
public ChannelFuture handshake(Channel channel) {
if (channel == null) {
throw new NullPointerException("channel");
}
ObjectUtil.checkNotNull(channel, "channel");
return handshake(channel, channel.newPromise());
}
@ -498,9 +497,7 @@ public abstract class WebSocketClientHandshaker {
* Closing Frame that was received
*/
public ChannelFuture close(Channel channel, CloseWebSocketFrame frame) {
if (channel == null) {
throw new NullPointerException("channel");
}
ObjectUtil.checkNotNull(channel, "channel");
return close(channel, frame, channel.newPromise());
}
@ -515,9 +512,7 @@ public abstract class WebSocketClientHandshaker {
* the {@link ChannelPromise} to be notified when the closing handshake is done
*/
public ChannelFuture close(Channel channel, CloseWebSocketFrame frame, ChannelPromise promise) {
if (channel == null) {
throw new NullPointerException("channel");
}
ObjectUtil.checkNotNull(channel, "channel");
channel.writeAndFlush(frame, promise);
applyForceCloseTimeout(channel, promise);
return promise;

View File

@ -337,9 +337,7 @@ public abstract class WebSocketServerHandshaker {
* Closing Frame that was received
*/
public ChannelFuture close(Channel channel, CloseWebSocketFrame frame) {
if (channel == null) {
throw new NullPointerException("channel");
}
ObjectUtil.checkNotNull(channel, "channel");
return close(channel, frame, channel.newPromise());
}
@ -354,9 +352,7 @@ public abstract class WebSocketServerHandshaker {
* the {@link ChannelPromise} to be notified when the closing handshake is done
*/
public ChannelFuture close(Channel channel, CloseWebSocketFrame frame, ChannelPromise promise) {
if (channel == null) {
throw new NullPointerException("channel");
}
ObjectUtil.checkNotNull(channel, "channel");
return channel.writeAndFlush(frame, promise).addListener(ChannelFutureListener.CLOSE);
}

View File

@ -22,6 +22,7 @@ import io.netty.handler.codec.CodecException;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpRequest;
import io.netty.handler.codec.http.HttpResponse;
import io.netty.util.internal.ObjectUtil;
import java.util.ArrayList;
import java.util.Arrays;
@ -50,9 +51,7 @@ public class WebSocketClientExtensionHandler extends ChannelDuplexHandler {
* with fallback configuration.
*/
public WebSocketClientExtensionHandler(WebSocketClientExtensionHandshaker... extensionHandshakers) {
if (extensionHandshakers == null) {
throw new NullPointerException("extensionHandshakers");
}
ObjectUtil.checkNotNull(extensionHandshakers, "extensionHandshakers");
if (extensionHandshakers.length == 0) {
throw new IllegalArgumentException("extensionHandshakers must contains at least one handshaker");
}

View File

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

View File

@ -23,6 +23,7 @@ import io.netty.channel.ChannelPromise;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpRequest;
import io.netty.handler.codec.http.HttpResponse;
import io.netty.util.internal.ObjectUtil;
import java.util.ArrayList;
import java.util.Arrays;
@ -53,9 +54,7 @@ public class WebSocketServerExtensionHandler extends ChannelDuplexHandler {
* with fallback configuration.
*/
public WebSocketServerExtensionHandler(WebSocketServerExtensionHandshaker... extensionHandshakers) {
if (extensionHandshakers == null) {
throw new NullPointerException("extensionHandshakers");
}
ObjectUtil.checkNotNull(extensionHandshakers, "extensionHandshakers");
if (extensionHandshakers.length == 0) {
throw new IllegalArgumentException("extensionHandshakers must contains at least one handshaker");
}

View File

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

View File

@ -16,6 +16,7 @@
package io.netty.handler.codec.rtsp;
import io.netty.handler.codec.http.HttpVersion;
import io.netty.util.internal.ObjectUtil;
/**
* The version of RTSP.
@ -34,9 +35,7 @@ public final class RtspVersions {
* Otherwise, a new {@link HttpVersion} instance will be returned.
*/
public static HttpVersion valueOf(String text) {
if (text == null) {
throw new NullPointerException("text");
}
ObjectUtil.checkNotNull(text, "text");
text = text.trim().toUpperCase();
if ("RTSP/1.0".equals(text)) {

View File

@ -18,6 +18,7 @@ package io.netty.handler.codec.spdy;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.util.IllegalReferenceCountException;
import io.netty.util.internal.ObjectUtil;
import io.netty.util.internal.StringUtil;
/**
@ -44,10 +45,8 @@ public class DefaultSpdyDataFrame extends DefaultSpdyStreamFrame implements Spdy
*/
public DefaultSpdyDataFrame(int streamId, ByteBuf data) {
super(streamId);
if (data == null) {
throw new NullPointerException("data");
}
this.data = validate(data);
this.data = validate(
ObjectUtil.checkNotNull(data, "data"));
}
private static ByteBuf validate(ByteBuf data) {

View File

@ -16,6 +16,7 @@
package io.netty.handler.codec.spdy;
import io.netty.buffer.ByteBuf;
import io.netty.util.internal.ObjectUtil;
final class SpdyCodecUtil {
@ -286,9 +287,7 @@ final class SpdyCodecUtil {
* Validate a SPDY header name.
*/
static void validateHeaderName(CharSequence name) {
if (name == null) {
throw new NullPointerException("name");
}
ObjectUtil.checkNotNull(name, "name");
if (name.length() == 0) {
throw new IllegalArgumentException(
"name cannot be length zero");
@ -319,9 +318,7 @@ final class SpdyCodecUtil {
* Validate a SPDY header value. Does not validate max length.
*/
static void validateHeaderValue(CharSequence value) {
if (value == null) {
throw new NullPointerException("value");
}
ObjectUtil.checkNotNull(value, "value");
for (int i = 0; i < value.length(); i ++) {
char c = value.charAt(i);
if (c == 0) {

View File

@ -38,10 +38,10 @@ import static io.netty.handler.codec.spdy.SpdyCodecUtil.getSignedInt;
import static io.netty.handler.codec.spdy.SpdyCodecUtil.getUnsignedInt;
import static io.netty.handler.codec.spdy.SpdyCodecUtil.getUnsignedMedium;
import static io.netty.handler.codec.spdy.SpdyCodecUtil.getUnsignedShort;
import static io.netty.util.internal.ObjectUtil.checkPositive;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.util.internal.ObjectUtil;
/**
* Decodes {@link ByteBuf}s into SPDY Frames.
@ -91,16 +91,9 @@ public class SpdyFrameDecoder {
* Creates a new instance with the specified parameters.
*/
public SpdyFrameDecoder(SpdyVersion spdyVersion, SpdyFrameDecoderDelegate delegate, int maxChunkSize) {
if (spdyVersion == null) {
throw new NullPointerException("spdyVersion");
}
if (delegate == null) {
throw new NullPointerException("delegate");
}
checkPositive(maxChunkSize, "maxChunkSize");
this.spdyVersion = spdyVersion.getVersion();
this.delegate = delegate;
this.maxChunkSize = maxChunkSize;
this.spdyVersion = ObjectUtil.checkNotNull(spdyVersion, "spdyVersion").getVersion();
this.delegate = ObjectUtil.checkNotNull(delegate, "delegate");
this.maxChunkSize = ObjectUtil.checkPositive(maxChunkSize, "maxChunkSize");
state = State.READ_COMMON_HEADER;
}

View File

@ -17,6 +17,7 @@ package io.netty.handler.codec.spdy;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.util.internal.ObjectUtil;
import java.nio.ByteOrder;
import java.util.Set;
@ -34,10 +35,7 @@ public class SpdyFrameEncoder {
* Creates a new instance with the specified {@code spdyVersion}.
*/
public SpdyFrameEncoder(SpdyVersion spdyVersion) {
if (spdyVersion == null) {
throw new NullPointerException("spdyVersion");
}
version = spdyVersion.getVersion();
version = ObjectUtil.checkNotNull(spdyVersion, "spdyVersion").getVersion();
}
private void writeControlFrameHeader(ByteBuf buffer, int type, byte flags, int length) {

View File

@ -17,8 +17,9 @@ package io.netty.handler.codec.spdy;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.util.internal.ObjectUtil;
import static io.netty.handler.codec.spdy.SpdyCodecUtil.*;
import static io.netty.handler.codec.spdy.SpdyCodecUtil.getSignedInt;
public class SpdyHeaderBlockRawDecoder extends SpdyHeaderBlockDecoder {
@ -48,9 +49,7 @@ public class SpdyHeaderBlockRawDecoder extends SpdyHeaderBlockDecoder {
}
public SpdyHeaderBlockRawDecoder(SpdyVersion spdyVersion, int maxHeaderSize) {
if (spdyVersion == null) {
throw new NullPointerException("spdyVersion");
}
ObjectUtil.checkNotNull(spdyVersion, "spdyVersion");
this.maxHeaderSize = maxHeaderSize;
state = State.READ_NUM_HEADERS;
}
@ -63,12 +62,8 @@ public class SpdyHeaderBlockRawDecoder extends SpdyHeaderBlockDecoder {
@Override
void decode(ByteBufAllocator alloc, ByteBuf headerBlock, SpdyHeadersFrame frame) throws Exception {
if (headerBlock == null) {
throw new NullPointerException("headerBlock");
}
if (frame == null) {
throw new NullPointerException("frame");
}
ObjectUtil.checkNotNull(headerBlock, "headerBlock");
ObjectUtil.checkNotNull(frame, "frame");
if (cumulation == null) {
decodeHeaderBlock(headerBlock, frame);

View File

@ -19,6 +19,7 @@ import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.ByteBufUtil;
import io.netty.buffer.Unpooled;
import io.netty.util.internal.ObjectUtil;
import java.util.Set;
@ -29,10 +30,7 @@ public class SpdyHeaderBlockRawEncoder extends SpdyHeaderBlockEncoder {
private final int version;
public SpdyHeaderBlockRawEncoder(SpdyVersion version) {
if (version == null) {
throw new NullPointerException("version");
}
this.version = version.getVersion();
this.version = ObjectUtil.checkNotNull(version, "version").getVersion();
}
private static void setLengthField(ByteBuf buffer, int writerIndex, int length) {

View File

@ -32,6 +32,7 @@ import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.handler.codec.http.HttpVersion;
import io.netty.handler.codec.spdy.SpdyHttpHeaders.Names;
import io.netty.util.ReferenceCountUtil;
import io.netty.util.internal.ObjectUtil;
import java.util.HashMap;
import java.util.List;
@ -101,12 +102,8 @@ public class SpdyHttpDecoder extends MessageToMessageDecoder<SpdyFrame> {
*/
protected SpdyHttpDecoder(SpdyVersion version, int maxContentLength, Map<Integer,
FullHttpMessage> messageMap, boolean validateHeaders) {
if (version == null) {
throw new NullPointerException("version");
}
checkPositive(maxContentLength, "maxContentLength");
spdyVersion = version.getVersion();
this.maxContentLength = maxContentLength;
spdyVersion = ObjectUtil.checkNotNull(version, "version").getVersion();
this.maxContentLength = checkPositive(maxContentLength, "maxContentLength");
this.messageMap = messageMap;
this.validateHeaders = validateHeaders;
}

View File

@ -28,6 +28,7 @@ import io.netty.handler.codec.http.HttpRequest;
import io.netty.handler.codec.http.HttpResponse;
import io.netty.handler.codec.http.LastHttpContent;
import io.netty.util.AsciiString;
import io.netty.util.internal.ObjectUtil;
import java.util.Iterator;
import java.util.List;
@ -144,9 +145,7 @@ public class SpdyHttpEncoder extends MessageToMessageEncoder<HttpObject> {
* @param validateHeaders validate the header names and values when adding them to the {@link SpdyHeaders}
*/
public SpdyHttpEncoder(SpdyVersion version, boolean headersToLowerCase, boolean validateHeaders) {
if (version == null) {
throw new NullPointerException("version");
}
ObjectUtil.checkNotNull(version, "version");
this.headersToLowerCase = headersToLowerCase;
this.validateHeaders = validateHeaders;
}

View File

@ -20,6 +20,7 @@ import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPromise;
import io.netty.util.internal.ObjectUtil;
import io.netty.util.internal.ThrowableUtil;
import java.util.concurrent.atomic.AtomicInteger;
@ -70,11 +71,8 @@ public class SpdySessionHandler extends ChannelDuplexHandler {
* handle the client endpoint of the connection.
*/
public SpdySessionHandler(SpdyVersion version, boolean server) {
if (version == null) {
throw new NullPointerException("version");
}
this.minorVersion = ObjectUtil.checkNotNull(version, "version").getMinorVersion();
this.server = server;
minorVersion = version.getMinorVersion();
}
public void setSessionReceiveWindowSize(int sessionReceiveWindowSize) {

View File

@ -15,6 +15,8 @@
*/
package io.netty.handler.codec.spdy;
import io.netty.util.internal.ObjectUtil;
/**
* The SPDY session status code and its description.
*/
@ -65,12 +67,8 @@ public class SpdySessionStatus implements Comparable<SpdySessionStatus> {
* {@code statusPhrase}.
*/
public SpdySessionStatus(int code, String statusPhrase) {
if (statusPhrase == null) {
throw new NullPointerException("statusPhrase");
}
this.statusPhrase = ObjectUtil.checkNotNull(statusPhrase, "statusPhrase");
this.code = code;
this.statusPhrase = statusPhrase;
}
/**

View File

@ -15,6 +15,8 @@
*/
package io.netty.handler.codec.spdy;
import io.netty.util.internal.ObjectUtil;
/**
* The SPDY stream status code and its description.
*/
@ -139,12 +141,8 @@ public class SpdyStreamStatus implements Comparable<SpdyStreamStatus> {
"0 is not a valid status code for a RST_STREAM");
}
if (statusPhrase == null) {
throw new NullPointerException("statusPhrase");
}
this.statusPhrase = ObjectUtil.checkNotNull(statusPhrase, "statusPhrase");
this.code = code;
this.statusPhrase = statusPhrase;
}
/**

View File

@ -62,9 +62,7 @@ public final class Http2StreamChannelBootstrap {
*/
@SuppressWarnings("unchecked")
public <T> Http2StreamChannelBootstrap option(ChannelOption<T> option, T value) {
if (option == null) {
throw new NullPointerException("option");
}
ObjectUtil.checkNotNull(option, "option");
if (value == null) {
options.remove(option);
} else {
@ -79,9 +77,7 @@ public final class Http2StreamChannelBootstrap {
*/
@SuppressWarnings("unchecked")
public <T> Http2StreamChannelBootstrap attr(AttributeKey<T> key, T value) {
if (key == null) {
throw new NullPointerException("key");
}
ObjectUtil.checkNotNull(key, "key");
if (value == null) {
attrs.remove(key);
} else {

View File

@ -72,11 +72,10 @@ public class InboundHttp2ToHttpAdapter extends Http2EventAdapter {
protected InboundHttp2ToHttpAdapter(Http2Connection connection, int maxContentLength,
boolean validateHttpHeaders, boolean propagateSettings) {
checkNotNull(connection, "connection");
if (maxContentLength <= 0) {
throw new IllegalArgumentException("maxContentLength: " + maxContentLength + " (expected: > 0)");
}
this.connection = connection;
this.connection = checkNotNull(connection, "connection");
this.maxContentLength = maxContentLength;
this.validateHttpHeaders = validateHttpHeaders;
this.propagateSettings = propagateSettings;

View File

@ -31,6 +31,7 @@
*/
package io.netty.handler.codec.http2;
import io.netty.util.internal.ObjectUtil;
import io.netty.util.internal.ResourcesUtil;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -57,9 +58,7 @@ public class HpackTest {
@Parameters(name = "{0}")
public static Collection<Object[]> data() {
File[] files = ResourcesUtil.getFile(HpackTest.class, TEST_DIR).listFiles();
if (files == null) {
throw new NullPointerException("files");
}
ObjectUtil.checkNotNull(files, "files");
ArrayList<Object[]> data = new ArrayList<Object[]>();
for (File file : files) {

View File

@ -17,6 +17,7 @@ package io.netty.handler.codec.memcache;
import io.netty.handler.codec.DecoderResult;
import io.netty.util.AbstractReferenceCounted;
import io.netty.util.internal.ObjectUtil;
import io.netty.util.internal.UnstableApi;
/**
@ -38,10 +39,6 @@ public abstract class AbstractMemcacheObject extends AbstractReferenceCounted im
@Override
public void setDecoderResult(DecoderResult result) {
if (result == null) {
throw new NullPointerException("DecoderResult should not be null.");
}
decoderResult = result;
this.decoderResult = ObjectUtil.checkNotNull(result, "DecoderResult should not be null.");
}
}

View File

@ -16,6 +16,7 @@
package io.netty.handler.codec.memcache;
import io.netty.buffer.ByteBuf;
import io.netty.util.internal.ObjectUtil;
import io.netty.util.internal.StringUtil;
import io.netty.util.internal.UnstableApi;
@ -31,10 +32,7 @@ public class DefaultMemcacheContent extends AbstractMemcacheObject implements Me
* Creates a new instance with the specified content.
*/
public DefaultMemcacheContent(ByteBuf content) {
if (content == null) {
throw new NullPointerException("Content cannot be null.");
}
this.content = content;
this.content = ObjectUtil.checkNotNull(content, "content");
}
@Override

View File

@ -17,6 +17,7 @@ package io.netty.handler.codec.memcache.binary;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.util.internal.ObjectUtil;
import io.netty.util.internal.UnstableApi;
/**
@ -48,11 +49,7 @@ public class DefaultFullBinaryMemcacheRequest extends DefaultBinaryMemcacheReque
public DefaultFullBinaryMemcacheRequest(ByteBuf key, ByteBuf extras,
ByteBuf content) {
super(key, extras);
if (content == null) {
throw new NullPointerException("Supplied content is null.");
}
this.content = content;
this.content = ObjectUtil.checkNotNull(content, "content");
setTotalBodyLength(keyLength() + extrasLength() + content.readableBytes());
}

View File

@ -17,6 +17,7 @@ package io.netty.handler.codec.memcache.binary;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.util.internal.ObjectUtil;
import io.netty.util.internal.UnstableApi;
/**
@ -48,11 +49,7 @@ public class DefaultFullBinaryMemcacheResponse extends DefaultBinaryMemcacheResp
public DefaultFullBinaryMemcacheResponse(ByteBuf key, ByteBuf extras,
ByteBuf content) {
super(key, extras);
if (content == null) {
throw new NullPointerException("Supplied content is null.");
}
this.content = content;
this.content = ObjectUtil.checkNotNull(content, "content");
setTotalBodyLength(keyLength() + extrasLength() + content.readableBytes());
}

View File

@ -16,6 +16,7 @@
package io.netty.handler.codec.mqtt;
import io.netty.util.internal.ObjectUtil;
import io.netty.util.internal.StringUtil;
import java.util.ArrayList;
@ -30,9 +31,7 @@ public class MqttSubAckPayload {
private final List<Integer> grantedQoSLevels;
public MqttSubAckPayload(int... grantedQoSLevels) {
if (grantedQoSLevels == null) {
throw new NullPointerException("grantedQoSLevels");
}
ObjectUtil.checkNotNull(grantedQoSLevels, "grantedQoSLevels");
List<Integer> list = new ArrayList<Integer>(grantedQoSLevels.length);
for (int v: grantedQoSLevels) {
@ -42,9 +41,7 @@ public class MqttSubAckPayload {
}
public MqttSubAckPayload(Iterable<Integer> grantedQoSLevels) {
if (grantedQoSLevels == null) {
throw new NullPointerException("grantedQoSLevels");
}
ObjectUtil.checkNotNull(grantedQoSLevels, "grantedQoSLevels");
List<Integer> list = new ArrayList<Integer>();
for (Integer v: grantedQoSLevels) {
if (v == null) {

View File

@ -17,6 +17,7 @@ package io.netty.handler.codec.socks;
import io.netty.buffer.ByteBuf;
import io.netty.util.CharsetUtil;
import io.netty.util.internal.ObjectUtil;
import java.nio.charset.CharsetEncoder;
@ -33,12 +34,8 @@ public final class SocksAuthRequest extends SocksRequest {
public SocksAuthRequest(String username, String password) {
super(SocksRequestType.AUTH);
if (username == null) {
throw new NullPointerException("username");
}
if (password == null) {
throw new NullPointerException("username");
}
ObjectUtil.checkNotNull(username, "username");
ObjectUtil.checkNotNull(password, "password");
final CharsetEncoder asciiEncoder = CharsetUtil.encoder(CharsetUtil.US_ASCII);
if (!asciiEncoder.canEncode(username) || !asciiEncoder.canEncode(password)) {
throw new IllegalArgumentException(

View File

@ -16,6 +16,7 @@
package io.netty.handler.codec.socks;
import io.netty.buffer.ByteBuf;
import io.netty.util.internal.ObjectUtil;
/**
* An socks auth response.
@ -29,10 +30,7 @@ public final class SocksAuthResponse extends SocksResponse {
public SocksAuthResponse(SocksAuthStatus authStatus) {
super(SocksResponseType.AUTH);
if (authStatus == null) {
throw new NullPointerException("authStatus");
}
this.authStatus = authStatus;
this.authStatus = ObjectUtil.checkNotNull(authStatus, "authStatus");
}
/**

View File

@ -18,6 +18,7 @@ package io.netty.handler.codec.socks;
import io.netty.buffer.ByteBuf;
import io.netty.util.CharsetUtil;
import io.netty.util.NetUtil;
import io.netty.util.internal.ObjectUtil;
import java.net.IDN;
@ -35,15 +36,10 @@ public final class SocksCmdRequest extends SocksRequest {
public SocksCmdRequest(SocksCmdType cmdType, SocksAddressType addressType, String host, int port) {
super(SocksRequestType.CMD);
if (cmdType == null) {
throw new NullPointerException("cmdType");
}
if (addressType == null) {
throw new NullPointerException("addressType");
}
if (host == null) {
throw new NullPointerException("host");
}
ObjectUtil.checkNotNull(cmdType, "cmdType");
ObjectUtil.checkNotNull(addressType, "addressType");
ObjectUtil.checkNotNull(host, "host");
switch (addressType) {
case IPv4:
if (!NetUtil.isValidIpV4Address(host)) {

View File

@ -18,6 +18,7 @@ package io.netty.handler.codec.socks;
import io.netty.buffer.ByteBuf;
import io.netty.util.CharsetUtil;
import io.netty.util.NetUtil;
import io.netty.util.internal.ObjectUtil;
import java.net.IDN;
@ -61,12 +62,8 @@ public final class SocksCmdResponse extends SocksResponse {
*/
public SocksCmdResponse(SocksCmdStatus cmdStatus, SocksAddressType addressType, String host, int port) {
super(SocksResponseType.CMD);
if (cmdStatus == null) {
throw new NullPointerException("cmdStatus");
}
if (addressType == null) {
throw new NullPointerException("addressType");
}
ObjectUtil.checkNotNull(cmdStatus, "cmdStatus");
ObjectUtil.checkNotNull(addressType, "addressType");
if (host != null) {
switch (addressType) {
case IPv4:

View File

@ -16,6 +16,7 @@
package io.netty.handler.codec.socks;
import io.netty.buffer.ByteBuf;
import io.netty.util.internal.ObjectUtil;
import java.util.Collections;
import java.util.List;
@ -31,10 +32,7 @@ public final class SocksInitRequest extends SocksRequest {
public SocksInitRequest(List<SocksAuthScheme> authSchemes) {
super(SocksRequestType.INIT);
if (authSchemes == null) {
throw new NullPointerException("authSchemes");
}
this.authSchemes = authSchemes;
this.authSchemes = ObjectUtil.checkNotNull(authSchemes, "authSchemes");
}
/**

View File

@ -16,6 +16,7 @@
package io.netty.handler.codec.socks;
import io.netty.buffer.ByteBuf;
import io.netty.util.internal.ObjectUtil;
/**
* An socks init response.
@ -28,10 +29,7 @@ public final class SocksInitResponse extends SocksResponse {
public SocksInitResponse(SocksAuthScheme authScheme) {
super(SocksResponseType.INIT);
if (authScheme == null) {
throw new NullPointerException("authScheme");
}
this.authScheme = authScheme;
this.authScheme = ObjectUtil.checkNotNull(authScheme, "authScheme");
}
/**

View File

@ -16,6 +16,7 @@
package io.netty.handler.codec.socks;
import io.netty.buffer.ByteBuf;
import io.netty.util.internal.ObjectUtil;
/**
* An abstract class that defines a SocksMessage, providing common properties for
@ -30,10 +31,7 @@ public abstract class SocksMessage {
private final SocksProtocolVersion protocolVersion = SocksProtocolVersion.SOCKS5;
protected SocksMessage(SocksMessageType type) {
if (type == null) {
throw new NullPointerException("type");
}
this.type = type;
this.type = ObjectUtil.checkNotNull(type, "type");
}
/**

View File

@ -15,6 +15,8 @@
*/
package io.netty.handler.codec.socks;
import io.netty.util.internal.ObjectUtil;
/**
* An abstract class that defines a SocksRequest, providing common properties for
* {@link SocksInitRequest}, {@link SocksAuthRequest}, {@link SocksCmdRequest} and {@link UnknownSocksRequest}.
@ -29,10 +31,7 @@ public abstract class SocksRequest extends SocksMessage {
protected SocksRequest(SocksRequestType requestType) {
super(SocksMessageType.REQUEST);
if (requestType == null) {
throw new NullPointerException("requestType");
}
this.requestType = requestType;
this.requestType = ObjectUtil.checkNotNull(requestType, "requestType");
}
/**

View File

@ -15,6 +15,8 @@
*/
package io.netty.handler.codec.socks;
import io.netty.util.internal.ObjectUtil;
/**
* An abstract class that defines a SocksResponse, providing common properties for
* {@link SocksInitResponse}, {@link SocksAuthResponse}, {@link SocksCmdResponse} and {@link UnknownSocksResponse}.
@ -29,10 +31,7 @@ public abstract class SocksResponse extends SocksMessage {
protected SocksResponse(SocksResponseType responseType) {
super(SocksMessageType.RESPONSE);
if (responseType == null) {
throw new NullPointerException("responseType");
}
this.responseType = responseType;
this.responseType = ObjectUtil.checkNotNull(responseType, "responseType");
}
/**

View File

@ -17,6 +17,7 @@
package io.netty.handler.codec.socksx;
import io.netty.handler.codec.DecoderResult;
import io.netty.util.internal.ObjectUtil;
/**
* An abstract {@link SocksMessage}.
@ -32,9 +33,6 @@ public abstract class AbstractSocksMessage implements SocksMessage {
@Override
public void setDecoderResult(DecoderResult decoderResult) {
if (decoderResult == null) {
throw new NullPointerException("decoderResult");
}
this.decoderResult = decoderResult;
this.decoderResult = ObjectUtil.checkNotNull(decoderResult, "decoderResult");
}
}

View File

@ -25,6 +25,7 @@ import io.netty.handler.codec.socksx.v4.Socks4ServerEncoder;
import io.netty.handler.codec.socksx.v5.Socks5AddressEncoder;
import io.netty.handler.codec.socksx.v5.Socks5InitialRequestDecoder;
import io.netty.handler.codec.socksx.v5.Socks5ServerEncoder;
import io.netty.util.internal.ObjectUtil;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;
@ -53,11 +54,7 @@ public class SocksPortUnificationServerHandler extends ByteToMessageDecoder {
* This constructor is useful when a user wants to use an alternative {@link Socks5AddressEncoder}.
*/
public SocksPortUnificationServerHandler(Socks5ServerEncoder socks5encoder) {
if (socks5encoder == null) {
throw new NullPointerException("socks5encoder");
}
this.socks5encoder = socks5encoder;
this.socks5encoder = ObjectUtil.checkNotNull(socks5encoder, "socks5encoder");
}
@Override

View File

@ -16,6 +16,7 @@
package io.netty.handler.codec.socksx.v4;
import io.netty.handler.codec.DecoderResult;
import io.netty.util.internal.ObjectUtil;
import io.netty.util.internal.StringUtil;
import java.net.IDN;
@ -50,22 +51,13 @@ public class DefaultSocks4CommandRequest extends AbstractSocks4Message implement
* @param userId the {@code USERID} field of the request
*/
public DefaultSocks4CommandRequest(Socks4CommandType type, String dstAddr, int dstPort, String userId) {
if (type == null) {
throw new NullPointerException("type");
}
if (dstAddr == null) {
throw new NullPointerException("dstAddr");
}
if (dstPort <= 0 || dstPort >= 65536) {
throw new IllegalArgumentException("dstPort: " + dstPort + " (expected: 1~65535)");
}
if (userId == null) {
throw new NullPointerException("userId");
}
this.userId = userId;
this.type = type;
this.dstAddr = IDN.toASCII(dstAddr);
this.type = ObjectUtil.checkNotNull(type, "type");
this.dstAddr = IDN.toASCII(
ObjectUtil.checkNotNull(dstAddr, "dstAddr"));
this.userId = ObjectUtil.checkNotNull(userId, "userId");
this.dstPort = dstPort;
}

View File

@ -17,6 +17,7 @@ package io.netty.handler.codec.socksx.v4;
import io.netty.handler.codec.DecoderResult;
import io.netty.util.NetUtil;
import io.netty.util.internal.ObjectUtil;
import io.netty.util.internal.StringUtil;
/**
@ -45,9 +46,6 @@ public class DefaultSocks4CommandResponse extends AbstractSocks4Message implemen
* @param dstPort the {@code DSTPORT} field of the response
*/
public DefaultSocks4CommandResponse(Socks4CommandStatus status, String dstAddr, int dstPort) {
if (status == null) {
throw new NullPointerException("cmdStatus");
}
if (dstAddr != null) {
if (!NetUtil.isValidIpV4Address(dstAddr)) {
throw new IllegalArgumentException(
@ -58,7 +56,7 @@ public class DefaultSocks4CommandResponse extends AbstractSocks4Message implemen
throw new IllegalArgumentException("dstPort: " + dstPort + " (expected: 0~65535)");
}
this.status = status;
this.status = ObjectUtil.checkNotNull(status, "cmdStatus");
this.dstAddr = dstAddr;
this.dstPort = dstPort;
}

View File

@ -15,6 +15,8 @@
*/
package io.netty.handler.codec.socksx.v4;
import io.netty.util.internal.ObjectUtil;
/**
* The status of {@link Socks4CommandResponse}.
*/
@ -49,12 +51,8 @@ public class Socks4CommandStatus implements Comparable<Socks4CommandStatus> {
}
public Socks4CommandStatus(int byteValue, String name) {
if (name == null) {
throw new NullPointerException("name");
}
this.name = ObjectUtil.checkNotNull(name, "name");
this.byteValue = (byte) byteValue;
this.name = name;
}
public byte byteValue() {

View File

@ -15,6 +15,8 @@
*/
package io.netty.handler.codec.socksx.v4;
import io.netty.util.internal.ObjectUtil;
/**
* The type of {@link Socks4CommandRequest}.
*/
@ -43,11 +45,8 @@ public class Socks4CommandType implements Comparable<Socks4CommandType> {
}
public Socks4CommandType(int byteValue, String name) {
if (name == null) {
throw new NullPointerException("name");
}
this.name = ObjectUtil.checkNotNull(name, "name");
this.byteValue = (byte) byteValue;
this.name = name;
}
public byte byteValue() {

View File

@ -17,6 +17,7 @@ package io.netty.handler.codec.socksx.v5;
import io.netty.handler.codec.DecoderResult;
import io.netty.util.NetUtil;
import io.netty.util.internal.ObjectUtil;
import io.netty.util.internal.StringUtil;
import java.net.IDN;
@ -34,15 +35,9 @@ public final class DefaultSocks5CommandRequest extends AbstractSocks5Message imp
public DefaultSocks5CommandRequest(
Socks5CommandType type, Socks5AddressType dstAddrType, String dstAddr, int dstPort) {
if (type == null) {
throw new NullPointerException("type");
}
if (dstAddrType == null) {
throw new NullPointerException("dstAddrType");
}
if (dstAddr == null) {
throw new NullPointerException("dstAddr");
}
this.type = ObjectUtil.checkNotNull(type, "type");
ObjectUtil.checkNotNull(dstAddrType, "dstAddrType");
ObjectUtil.checkNotNull(dstAddr, "dstAddr");
if (dstAddrType == Socks5AddressType.IPv4) {
if (!NetUtil.isValidIpV4Address(dstAddr)) {
@ -63,7 +58,6 @@ public final class DefaultSocks5CommandRequest extends AbstractSocks5Message imp
throw new IllegalArgumentException("dstPort: " + dstPort + " (expected: 0~65535)");
}
this.type = type;
this.dstAddrType = dstAddrType;
this.dstAddr = dstAddr;
this.dstPort = dstPort;

View File

@ -17,6 +17,7 @@ package io.netty.handler.codec.socksx.v5;
import io.netty.handler.codec.DecoderResult;
import io.netty.util.NetUtil;
import io.netty.util.internal.ObjectUtil;
import io.netty.util.internal.StringUtil;
import java.net.IDN;
@ -38,12 +39,9 @@ public final class DefaultSocks5CommandResponse extends AbstractSocks5Message im
public DefaultSocks5CommandResponse(
Socks5CommandStatus status, Socks5AddressType bndAddrType, String bndAddr, int bndPort) {
if (status == null) {
throw new NullPointerException("status");
}
if (bndAddrType == null) {
throw new NullPointerException("bndAddrType");
}
ObjectUtil.checkNotNull(status, "status");
ObjectUtil.checkNotNull(bndAddrType, "bndAddrType");
if (bndAddr != null) {
if (bndAddrType == Socks5AddressType.IPv4) {
if (!NetUtil.isValidIpV4Address(bndAddr)) {

View File

@ -16,6 +16,7 @@
package io.netty.handler.codec.socksx.v5;
import io.netty.handler.codec.DecoderResult;
import io.netty.util.internal.ObjectUtil;
import io.netty.util.internal.StringUtil;
import java.util.ArrayList;
@ -30,9 +31,7 @@ public class DefaultSocks5InitialRequest extends AbstractSocks5Message implement
private final List<Socks5AuthMethod> authMethods;
public DefaultSocks5InitialRequest(Socks5AuthMethod... authMethods) {
if (authMethods == null) {
throw new NullPointerException("authMethods");
}
ObjectUtil.checkNotNull(authMethods, "authMethods");
List<Socks5AuthMethod> list = new ArrayList<Socks5AuthMethod>(authMethods.length);
for (Socks5AuthMethod m: authMethods) {
@ -50,9 +49,7 @@ public class DefaultSocks5InitialRequest extends AbstractSocks5Message implement
}
public DefaultSocks5InitialRequest(Iterable<Socks5AuthMethod> authMethods) {
if (authMethods == null) {
throw new NullPointerException("authSchemes");
}
ObjectUtil.checkNotNull(authMethods, "authSchemes");
List<Socks5AuthMethod> list = new ArrayList<Socks5AuthMethod>();
for (Socks5AuthMethod m: authMethods) {

View File

@ -16,6 +16,7 @@
package io.netty.handler.codec.socksx.v5;
import io.netty.handler.codec.DecoderResult;
import io.netty.util.internal.ObjectUtil;
import io.netty.util.internal.StringUtil;
/**
@ -26,10 +27,7 @@ public class DefaultSocks5InitialResponse extends AbstractSocks5Message implemen
private final Socks5AuthMethod authMethod;
public DefaultSocks5InitialResponse(Socks5AuthMethod authMethod) {
if (authMethod == null) {
throw new NullPointerException("authMethod");
}
this.authMethod = authMethod;
this.authMethod = ObjectUtil.checkNotNull(authMethod, "authMethod");
}
@Override

View File

@ -16,6 +16,7 @@
package io.netty.handler.codec.socksx.v5;
import io.netty.handler.codec.DecoderResult;
import io.netty.util.internal.ObjectUtil;
import io.netty.util.internal.StringUtil;
/**
@ -27,12 +28,8 @@ public class DefaultSocks5PasswordAuthRequest extends AbstractSocks5Message impl
private final String password;
public DefaultSocks5PasswordAuthRequest(String username, String password) {
if (username == null) {
throw new NullPointerException("username");
}
if (password == null) {
throw new NullPointerException("password");
}
ObjectUtil.checkNotNull(username, "username");
ObjectUtil.checkNotNull(password, "password");
if (username.length() > 255) {
throw new IllegalArgumentException("username: **** (expected: less than 256 chars)");

View File

@ -16,6 +16,7 @@
package io.netty.handler.codec.socksx.v5;
import io.netty.handler.codec.DecoderResult;
import io.netty.util.internal.ObjectUtil;
import io.netty.util.internal.StringUtil;
/**
@ -26,11 +27,7 @@ public class DefaultSocks5PasswordAuthResponse extends AbstractSocks5Message imp
private final Socks5PasswordAuthStatus status;
public DefaultSocks5PasswordAuthResponse(Socks5PasswordAuthStatus status) {
if (status == null) {
throw new NullPointerException("status");
}
this.status = status;
this.status = ObjectUtil.checkNotNull(status, "status");
}
@Override

View File

@ -16,6 +16,8 @@
package io.netty.handler.codec.socksx.v5;
import io.netty.util.internal.ObjectUtil;
/**
* The type of address in {@link Socks5CommandRequest} and {@link Socks5CommandResponse}.
*/
@ -47,12 +49,8 @@ public class Socks5AddressType implements Comparable<Socks5AddressType> {
}
public Socks5AddressType(int byteValue, String name) {
if (name == null) {
throw new NullPointerException("name");
}
this.name = ObjectUtil.checkNotNull(name, "name");
this.byteValue = (byte) byteValue;
this.name = name;
}
public byte byteValue() {

View File

@ -16,6 +16,8 @@
package io.netty.handler.codec.socksx.v5;
import io.netty.util.internal.ObjectUtil;
/**
* The authentication method of SOCKS5.
*/
@ -54,12 +56,8 @@ public class Socks5AuthMethod implements Comparable<Socks5AuthMethod> {
}
public Socks5AuthMethod(int byteValue, String name) {
if (name == null) {
throw new NullPointerException("name");
}
this.name = ObjectUtil.checkNotNull(name, "name");
this.byteValue = (byte) byteValue;
this.name = name;
}
public byte byteValue() {

View File

@ -22,6 +22,7 @@ import io.netty.channel.ChannelHandler.Sharable;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.EncoderException;
import io.netty.handler.codec.MessageToByteEncoder;
import io.netty.util.internal.ObjectUtil;
import io.netty.util.internal.StringUtil;
import java.util.List;
@ -48,11 +49,7 @@ public class Socks5ClientEncoder extends MessageToByteEncoder<Socks5Message> {
* Creates a new instance with the specified {@link Socks5AddressEncoder}.
*/
public Socks5ClientEncoder(Socks5AddressEncoder addressEncoder) {
if (addressEncoder == null) {
throw new NullPointerException("addressEncoder");
}
this.addressEncoder = addressEncoder;
this.addressEncoder = ObjectUtil.checkNotNull(addressEncoder, "addressEncoder");
}
/**

View File

@ -23,6 +23,7 @@ import io.netty.handler.codec.DecoderResult;
import io.netty.handler.codec.ReplayingDecoder;
import io.netty.handler.codec.socksx.SocksVersion;
import io.netty.handler.codec.socksx.v5.Socks5CommandRequestDecoder.State;
import io.netty.util.internal.ObjectUtil;
import java.util.List;
@ -48,11 +49,7 @@ public class Socks5CommandRequestDecoder extends ReplayingDecoder<State> {
public Socks5CommandRequestDecoder(Socks5AddressDecoder addressDecoder) {
super(State.INIT);
if (addressDecoder == null) {
throw new NullPointerException("addressDecoder");
}
this.addressDecoder = addressDecoder;
this.addressDecoder = ObjectUtil.checkNotNull(addressDecoder, "addressDecoder");
}
@Override

View File

@ -23,6 +23,7 @@ import io.netty.handler.codec.DecoderResult;
import io.netty.handler.codec.ReplayingDecoder;
import io.netty.handler.codec.socksx.SocksVersion;
import io.netty.handler.codec.socksx.v5.Socks5CommandResponseDecoder.State;
import io.netty.util.internal.ObjectUtil;
import java.util.List;
@ -48,11 +49,7 @@ public class Socks5CommandResponseDecoder extends ReplayingDecoder<State> {
public Socks5CommandResponseDecoder(Socks5AddressDecoder addressDecoder) {
super(State.INIT);
if (addressDecoder == null) {
throw new NullPointerException("addressDecoder");
}
this.addressDecoder = addressDecoder;
this.addressDecoder = ObjectUtil.checkNotNull(addressDecoder, "addressDecoder");
}
@Override

View File

@ -16,6 +16,8 @@
package io.netty.handler.codec.socksx.v5;
import io.netty.util.internal.ObjectUtil;
/**
* The status of {@link Socks5CommandResponse}.
*/
@ -65,12 +67,8 @@ public class Socks5CommandStatus implements Comparable<Socks5CommandStatus> {
}
public Socks5CommandStatus(int byteValue, String name) {
if (name == null) {
throw new NullPointerException("name");
}
this.name = ObjectUtil.checkNotNull(name, "name");
this.byteValue = (byte) byteValue;
this.name = name;
}
public byte byteValue() {

View File

@ -16,6 +16,8 @@
package io.netty.handler.codec.socksx.v5;
import io.netty.util.internal.ObjectUtil;
/**
* The type of {@link Socks5CommandRequest}.
*/
@ -47,12 +49,8 @@ public class Socks5CommandType implements Comparable<Socks5CommandType> {
}
public Socks5CommandType(int byteValue, String name) {
if (name == null) {
throw new NullPointerException("name");
}
this.name = ObjectUtil.checkNotNull(name, "name");
this.byteValue = (byte) byteValue;
this.name = name;
}
public byte byteValue() {

View File

@ -16,6 +16,8 @@
package io.netty.handler.codec.socksx.v5;
import io.netty.util.internal.ObjectUtil;
/**
* The status of {@link Socks5PasswordAuthResponse}.
*/
@ -44,12 +46,8 @@ public class Socks5PasswordAuthStatus implements Comparable<Socks5PasswordAuthSt
}
public Socks5PasswordAuthStatus(int byteValue, String name) {
if (name == null) {
throw new NullPointerException("name");
}
this.name = ObjectUtil.checkNotNull(name, "name");
this.byteValue = (byte) byteValue;
this.name = name;
}
public byte byteValue() {

View File

@ -21,6 +21,7 @@ import io.netty.channel.ChannelHandler.Sharable;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.EncoderException;
import io.netty.handler.codec.MessageToByteEncoder;
import io.netty.util.internal.ObjectUtil;
import io.netty.util.internal.StringUtil;
/**
@ -44,11 +45,7 @@ public class Socks5ServerEncoder extends MessageToByteEncoder<Socks5Message> {
* Creates a new instance with the specified {@link Socks5AddressEncoder}.
*/
public Socks5ServerEncoder(Socks5AddressEncoder addressEncoder) {
if (addressEncoder == null) {
throw new NullPointerException("addressEncoder");
}
this.addressEncoder = addressEncoder;
this.addressEncoder = ObjectUtil.checkNotNull(addressEncoder, "addressEncoder");
}
/**

View File

@ -18,6 +18,7 @@ package io.netty.handler.codec.stomp;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.util.CharsetUtil;
import io.netty.util.internal.ObjectUtil;
/**
* Default implementation of {@link StompFrame}.
@ -36,12 +37,7 @@ public class DefaultStompFrame extends DefaultStompHeadersSubframe implements St
DefaultStompFrame(StompCommand command, ByteBuf content, DefaultStompHeaders headers) {
super(command, headers);
if (content == null) {
throw new NullPointerException("content");
}
this.content = content;
this.content = ObjectUtil.checkNotNull(content, "content");
}
@Override

View File

@ -16,6 +16,7 @@
package io.netty.handler.codec.stomp;
import io.netty.handler.codec.DecoderResult;
import io.netty.util.internal.ObjectUtil;
/**
* Default implementation of {@link StompHeadersSubframe}.
@ -31,11 +32,7 @@ public class DefaultStompHeadersSubframe implements StompHeadersSubframe {
}
DefaultStompHeadersSubframe(StompCommand command, DefaultStompHeaders headers) {
if (command == null) {
throw new NullPointerException("command");
}
this.command = command;
this.command = ObjectUtil.checkNotNull(command, "command");
this.headers = headers == null ? new DefaultStompHeaders() : headers;
}

View File

@ -23,6 +23,7 @@ import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import io.netty.util.AsciiString;
import io.netty.util.CharsetUtil;
import io.netty.util.internal.ObjectUtil;
public final class AsciiHeadersEncoder {
@ -63,19 +64,9 @@ public final class AsciiHeadersEncoder {
}
public AsciiHeadersEncoder(ByteBuf buf, SeparatorType separatorType, NewlineType newlineType) {
if (buf == null) {
throw new NullPointerException("buf");
}
if (separatorType == null) {
throw new NullPointerException("separatorType");
}
if (newlineType == null) {
throw new NullPointerException("newlineType");
}
this.buf = buf;
this.separatorType = separatorType;
this.newlineType = newlineType;
this.buf = ObjectUtil.checkNotNull(buf, "buf");
this.separatorType = ObjectUtil.checkNotNull(separatorType, "separatorType");
this.newlineType = ObjectUtil.checkNotNull(newlineType, "newlineType");
}
public void encode(Entry<CharSequence, CharSequence> entry) {

View File

@ -25,6 +25,7 @@ import io.netty.channel.ChannelConfig;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.socket.ChannelInputShutdownEvent;
import io.netty.util.internal.ObjectUtil;
import io.netty.util.internal.StringUtil;
import java.util.List;
@ -197,10 +198,7 @@ public abstract class ByteToMessageDecoder extends ChannelInboundHandlerAdapter
* Set the {@link Cumulator} to use for cumulate the received {@link ByteBuf}s.
*/
public void setCumulator(Cumulator cumulator) {
if (cumulator == null) {
throw new NullPointerException("cumulator");
}
this.cumulator = cumulator;
this.cumulator = ObjectUtil.checkNotNull(cumulator, "cumulator");
}
/**

View File

@ -16,6 +16,7 @@
package io.netty.handler.codec;
import io.netty.util.Signal;
import io.netty.util.internal.ObjectUtil;
public class DecoderResult {
@ -26,19 +27,13 @@ public class DecoderResult {
public static final DecoderResult SUCCESS = new DecoderResult(SIGNAL_SUCCESS);
public static DecoderResult failure(Throwable cause) {
if (cause == null) {
throw new NullPointerException("cause");
}
return new DecoderResult(cause);
return new DecoderResult(ObjectUtil.checkNotNull(cause, "cause"));
}
private final Throwable cause;
protected DecoderResult(Throwable cause) {
if (cause == null) {
throw new NullPointerException("cause");
}
this.cause = cause;
this.cause = ObjectUtil.checkNotNull(cause, "cause");
}
public boolean isFinished() {

View File

@ -19,6 +19,7 @@ import static io.netty.util.internal.ObjectUtil.checkPositive;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.util.internal.ObjectUtil;
import java.util.List;
@ -166,12 +167,7 @@ public class DelimiterBasedFrameDecoder extends ByteToMessageDecoder {
public DelimiterBasedFrameDecoder(
int maxFrameLength, boolean stripDelimiter, boolean failFast, ByteBuf... delimiters) {
validateMaxFrameLength(maxFrameLength);
if (delimiters == null) {
throw new NullPointerException("delimiters");
}
if (delimiters.length == 0) {
throw new IllegalArgumentException("empty delimiters");
}
ObjectUtil.checkNonEmpty(delimiters, "delimiters");
if (isLineBased(delimiters) && !isSubclass()) {
lineBasedDecoder = new LineBasedFrameDecoder(maxFrameLength, stripDelimiter, failFast);
@ -339,9 +335,7 @@ public class DelimiterBasedFrameDecoder extends ByteToMessageDecoder {
}
private static void validateDelimiter(ByteBuf delimiter) {
if (delimiter == null) {
throw new NullPointerException("delimiter");
}
ObjectUtil.checkNotNull(delimiter, "delimiter");
if (!delimiter.isReadable()) {
throw new IllegalArgumentException("empty delimiter");
}

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