Motivation: NullChecks resulting in a NullPointerException or IllegalArgumentException, numeric ranges (>0, >=0) checks, not empty strings/arrays checks must never be anonymous but with the parameter or variable name which is checked. They must be specific and should not be done with an "OR-Logic" (if a == null || b == null) throw new NullPointerEx. Modifications: * import static relevant checks * Replace manual checks with ObjectUtil methods Result: All checks needed are done with ObjectUtil, some exception texts are improved. Fixes #11170
This commit is contained in:
parent
83297ed2ba
commit
eb563c25b4
@ -16,6 +16,8 @@
|
||||
package io.netty.channel.epoll;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
import static io.netty.util.internal.ObjectUtil.checkNotNullWithIAE;
|
||||
import static io.netty.util.internal.ObjectUtil.checkNonEmpty;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
@ -36,13 +38,8 @@ final class TcpMd5Util {
|
||||
// Validate incoming values
|
||||
for (Entry<InetAddress, byte[]> e : newKeys.entrySet()) {
|
||||
final byte[] key = e.getValue();
|
||||
if (e.getKey() == null) {
|
||||
throw new IllegalArgumentException("newKeys contains an entry with null address: " + newKeys);
|
||||
}
|
||||
requireNonNull(key, "newKeys[" + e.getKey() + "]");
|
||||
if (key.length == 0) {
|
||||
throw new IllegalArgumentException("newKeys[" + e.getKey() + "] has an empty key.");
|
||||
}
|
||||
checkNotNullWithIAE(e.getKey(), "e.getKey");
|
||||
checkNonEmpty(key, e.getKey().toString());
|
||||
if (key.length > Native.TCP_MD5SIG_MAXKEYLEN) {
|
||||
throw new IllegalArgumentException("newKeys[" + e.getKey() +
|
||||
"] has a key with invalid length; should not exceed the maximum length (" +
|
||||
|
@ -316,10 +316,11 @@ public class DefaultChannelConfig implements ChannelConfig {
|
||||
* is of type {@link MaxMessagesRecvByteBufAllocator}.
|
||||
*/
|
||||
private void setRecvByteBufAllocator(RecvByteBufAllocator allocator, ChannelMetadata metadata) {
|
||||
requireNonNull(allocator, "allocator");
|
||||
requireNonNull(metadata, "metadata");
|
||||
if (allocator instanceof MaxMessagesRecvByteBufAllocator) {
|
||||
((MaxMessagesRecvByteBufAllocator) allocator).maxMessagesPerRead(metadata.defaultMaxMessagesPerRead());
|
||||
}
|
||||
requireNonNull(allocator, "allocator");
|
||||
setRecvByteBufAllocator(allocator);
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
package io.netty.channel.local;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
import static io.netty.util.internal.ObjectUtil.checkNonEmptyAfterTrim;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
|
||||
@ -52,13 +52,8 @@ public final class LocalAddress extends SocketAddress implements Comparable<Loca
|
||||
* Creates a new instance with the specified ID.
|
||||
*/
|
||||
public LocalAddress(String id) {
|
||||
requireNonNull(id, "id");
|
||||
id = id.trim().toLowerCase();
|
||||
if (id.isEmpty()) {
|
||||
throw new IllegalArgumentException("empty id");
|
||||
}
|
||||
this.id = id;
|
||||
strVal = "local:" + id;
|
||||
this.id = checkNonEmptyAfterTrim(id, "id").toLowerCase();
|
||||
this.strVal = "local:" + this.id;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user