diff --git a/transport/src/main/java/io/netty/bootstrap/AbstractBootstrap.java b/transport/src/main/java/io/netty/bootstrap/AbstractBootstrap.java index 1030c32041..14bb7a9820 100644 --- a/transport/src/main/java/io/netty/bootstrap/AbstractBootstrap.java +++ b/transport/src/main/java/io/netty/bootstrap/AbstractBootstrap.java @@ -26,10 +26,11 @@ import io.netty.channel.DefaultChannelPromise; import io.netty.channel.EventLoop; import io.netty.channel.EventLoopGroup; import io.netty.channel.ReflectiveChannelFactory; -import io.netty.util.internal.SocketUtils; import io.netty.util.AttributeKey; import io.netty.util.concurrent.EventExecutor; import io.netty.util.concurrent.GlobalEventExecutor; +import io.netty.util.internal.ObjectUtil; +import io.netty.util.internal.SocketUtils; import io.netty.util.internal.StringUtil; import io.netty.util.internal.logging.InternalLogger; @@ -79,9 +80,7 @@ public abstract class AbstractBootstrap, C ext * {@link Channel} */ public B group(EventLoopGroup group) { - if (group == null) { - throw new NullPointerException("group"); - } + ObjectUtil.checkNotNull(group, "group"); if (this.group != null) { throw new IllegalStateException("group set already"); } @@ -100,10 +99,9 @@ public abstract class AbstractBootstrap, C ext * {@link Channel} implementation has no no-args constructor. */ public B channel(Class channelClass) { - if (channelClass == null) { - throw new NullPointerException("channelClass"); - } - return channelFactory(new ReflectiveChannelFactory(channelClass)); + return channelFactory(new ReflectiveChannelFactory( + ObjectUtil.checkNotNull(channelClass, "channelClass") + )); } /** @@ -111,9 +109,7 @@ public abstract class AbstractBootstrap, C ext */ @Deprecated public B channelFactory(ChannelFactory channelFactory) { - if (channelFactory == null) { - throw new NullPointerException("channelFactory"); - } + ObjectUtil.checkNotNull(channelFactory, "channelFactory"); if (this.channelFactory != null) { throw new IllegalStateException("channelFactory set already"); } @@ -168,9 +164,7 @@ public abstract class AbstractBootstrap, C ext * created. Use a value of {@code null} to remove a previous set {@link ChannelOption}. */ public B option(ChannelOption option, T value) { - if (option == null) { - throw new NullPointerException("option"); - } + ObjectUtil.checkNotNull(option, "option"); if (value == null) { synchronized (options) { options.remove(option); @@ -188,9 +182,7 @@ public abstract class AbstractBootstrap, C ext * {@code null}, the attribute of the specified {@code key} is removed. */ public B attr(AttributeKey key, T value) { - if (key == null) { - throw new NullPointerException("key"); - } + ObjectUtil.checkNotNull(key, "key"); if (value == null) { synchronized (attrs) { attrs.remove(key); @@ -272,10 +264,7 @@ public abstract class AbstractBootstrap, C ext */ public ChannelFuture bind(SocketAddress localAddress) { validate(); - if (localAddress == null) { - throw new NullPointerException("localAddress"); - } - return doBind(localAddress); + return doBind(ObjectUtil.checkNotNull(localAddress, "localAddress")); } private ChannelFuture doBind(final SocketAddress localAddress) { @@ -375,10 +364,7 @@ public abstract class AbstractBootstrap, C ext * the {@link ChannelHandler} to use for serving the requests. */ public B handler(ChannelHandler handler) { - if (handler == null) { - throw new NullPointerException("handler"); - } - this.handler = handler; + this.handler = ObjectUtil.checkNotNull(handler, "handler"); return self(); } diff --git a/transport/src/main/java/io/netty/bootstrap/Bootstrap.java b/transport/src/main/java/io/netty/bootstrap/Bootstrap.java index 1e2e483132..758475e536 100644 --- a/transport/src/main/java/io/netty/bootstrap/Bootstrap.java +++ b/transport/src/main/java/io/netty/bootstrap/Bootstrap.java @@ -30,6 +30,7 @@ import io.netty.resolver.AddressResolverGroup; import io.netty.util.AttributeKey; import io.netty.util.concurrent.Future; import io.netty.util.concurrent.FutureListener; +import io.netty.util.internal.ObjectUtil; import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLoggerFactory; @@ -137,10 +138,7 @@ public class Bootstrap extends AbstractBootstrap { * Connect a {@link Channel} to the remote peer. */ public ChannelFuture connect(SocketAddress remoteAddress) { - if (remoteAddress == null) { - throw new NullPointerException("remoteAddress"); - } - + ObjectUtil.checkNotNull(remoteAddress, "remoteAddress"); validate(); return doResolveAndConnect(remoteAddress, config.localAddress()); } @@ -149,9 +147,7 @@ public class Bootstrap extends AbstractBootstrap { * Connect a {@link Channel} to the remote peer. */ public ChannelFuture connect(SocketAddress remoteAddress, SocketAddress localAddress) { - if (remoteAddress == null) { - throw new NullPointerException("remoteAddress"); - } + ObjectUtil.checkNotNull(remoteAddress, "remoteAddress"); validate(); return doResolveAndConnect(remoteAddress, localAddress); } diff --git a/transport/src/main/java/io/netty/bootstrap/ServerBootstrap.java b/transport/src/main/java/io/netty/bootstrap/ServerBootstrap.java index 310e9fb9fe..33d858dbe5 100644 --- a/transport/src/main/java/io/netty/bootstrap/ServerBootstrap.java +++ b/transport/src/main/java/io/netty/bootstrap/ServerBootstrap.java @@ -28,6 +28,7 @@ import io.netty.channel.ChannelPipeline; import io.netty.channel.EventLoopGroup; import io.netty.channel.ServerChannel; import io.netty.util.AttributeKey; +import io.netty.util.internal.ObjectUtil; import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLoggerFactory; @@ -79,9 +80,7 @@ public class ServerBootstrap extends AbstractBootstrap ServerBootstrap childOption(ChannelOption childOption, T value) { - if (childOption == null) { - throw new NullPointerException("childOption"); - } + ObjectUtil.checkNotNull(childOption, "childOption"); if (value == null) { synchronized (childOptions) { childOptions.remove(childOption); @@ -115,9 +112,7 @@ public class ServerBootstrap extends AbstractBootstrap ServerBootstrap childAttr(AttributeKey childKey, T value) { - if (childKey == null) { - throw new NullPointerException("childKey"); - } + ObjectUtil.checkNotNull(childKey, "childKey"); if (value == null) { childAttrs.remove(childKey); } else { @@ -130,10 +125,7 @@ public class ServerBootstrap extends AbstractBootstrap