diff --git a/example/src/main/java/io/netty/example/http2/helloworld/frame/server/Http2ServerInitializer.java b/example/src/main/java/io/netty/example/http2/helloworld/frame/server/Http2ServerInitializer.java index f9d57d5080..b0df3bc54d 100644 --- a/example/src/main/java/io/netty/example/http2/helloworld/frame/server/Http2ServerInitializer.java +++ b/example/src/main/java/io/netty/example/http2/helloworld/frame/server/Http2ServerInitializer.java @@ -16,6 +16,8 @@ package io.netty.example.http2.helloworld.frame.server; +import static io.netty.util.internal.ObjectUtil.checkPositiveOrZero; + import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInitializer; @@ -58,11 +60,8 @@ public class Http2ServerInitializer extends ChannelInitializer { } public Http2ServerInitializer(SslContext sslCtx, int maxHttpContentLength) { - if (maxHttpContentLength < 0) { - throw new IllegalArgumentException("maxHttpContentLength (expected >= 0): " + maxHttpContentLength); - } this.sslCtx = sslCtx; - this.maxHttpContentLength = maxHttpContentLength; + this.maxHttpContentLength = checkPositiveOrZero(maxHttpContentLength, "maxHttpContentLength"); } @Override diff --git a/example/src/main/java/io/netty/example/http2/helloworld/multiplex/server/Http2ServerInitializer.java b/example/src/main/java/io/netty/example/http2/helloworld/multiplex/server/Http2ServerInitializer.java index be58cc93ab..ab89d7673c 100644 --- a/example/src/main/java/io/netty/example/http2/helloworld/multiplex/server/Http2ServerInitializer.java +++ b/example/src/main/java/io/netty/example/http2/helloworld/multiplex/server/Http2ServerInitializer.java @@ -16,6 +16,8 @@ package io.netty.example.http2.helloworld.multiplex.server; +import static io.netty.util.internal.ObjectUtil.checkPositiveOrZero; + import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInitializer; @@ -60,11 +62,8 @@ public class Http2ServerInitializer extends ChannelInitializer { } public Http2ServerInitializer(SslContext sslCtx, int maxHttpContentLength) { - if (maxHttpContentLength < 0) { - throw new IllegalArgumentException("maxHttpContentLength (expected >= 0): " + maxHttpContentLength); - } this.sslCtx = sslCtx; - this.maxHttpContentLength = maxHttpContentLength; + this.maxHttpContentLength = checkPositiveOrZero(maxHttpContentLength, "maxHttpContentLength"); } @Override diff --git a/example/src/main/java/io/netty/example/http2/helloworld/server/Http2ServerInitializer.java b/example/src/main/java/io/netty/example/http2/helloworld/server/Http2ServerInitializer.java index 962279d955..b322d083e3 100644 --- a/example/src/main/java/io/netty/example/http2/helloworld/server/Http2ServerInitializer.java +++ b/example/src/main/java/io/netty/example/http2/helloworld/server/Http2ServerInitializer.java @@ -16,6 +16,8 @@ package io.netty.example.http2.helloworld.server; +import static io.netty.util.internal.ObjectUtil.checkPositiveOrZero; + import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInitializer; @@ -56,11 +58,8 @@ public class Http2ServerInitializer extends ChannelInitializer { } public Http2ServerInitializer(SslContext sslCtx, int maxHttpContentLength) { - if (maxHttpContentLength < 0) { - throw new IllegalArgumentException("maxHttpContentLength (expected >= 0): " + maxHttpContentLength); - } this.sslCtx = sslCtx; - this.maxHttpContentLength = maxHttpContentLength; + this.maxHttpContentLength = checkPositiveOrZero(maxHttpContentLength, "maxHttpContentLength"); } @Override diff --git a/example/src/main/java/io/netty/example/worldclock/WorldClockProtocol.java b/example/src/main/java/io/netty/example/worldclock/WorldClockProtocol.java index dac603d52b..331eefc2d4 100644 --- a/example/src/main/java/io/netty/example/worldclock/WorldClockProtocol.java +++ b/example/src/main/java/io/netty/example/worldclock/WorldClockProtocol.java @@ -19,6 +19,8 @@ package io.netty.example.worldclock; +import static io.netty.util.internal.ObjectUtil.checkNotNull; + @SuppressWarnings("all") public final class WorldClockProtocol { private WorldClockProtocol() {} @@ -822,9 +824,7 @@ public final class WorldClockProtocol { * required .io.netty.example.worldclock.Continent continent = 1; */ public Builder setContinent(io.netty.example.worldclock.WorldClockProtocol.Continent value) { - if (value == null) { - throw new NullPointerException(); - } + checkNotNull(value, "value"); bitField0_ |= 0x00000001; continent_ = value; onChanged(); @@ -886,9 +886,7 @@ public final class WorldClockProtocol { */ public Builder setCity( java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } + checkNotNull(value, "value"); bitField0_ |= 0x00000002; city_ = value; onChanged(); @@ -908,9 +906,7 @@ public final class WorldClockProtocol { */ public Builder setCityBytes( com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } + checkNotNull(value, "value"); bitField0_ |= 0x00000002; city_ = value; onChanged(); @@ -1438,9 +1434,7 @@ public final class WorldClockProtocol { public Builder setLocation( int index, io.netty.example.worldclock.WorldClockProtocol.Location value) { if (locationBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } + checkNotNull(value, "value"); ensureLocationIsMutable(); location_.set(index, value); onChanged(); @@ -1468,9 +1462,7 @@ public final class WorldClockProtocol { */ public Builder addLocation(io.netty.example.worldclock.WorldClockProtocol.Location value) { if (locationBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } + checkNotNull(value, "value"); ensureLocationIsMutable(); location_.add(value); onChanged(); @@ -1485,9 +1477,7 @@ public final class WorldClockProtocol { public Builder addLocation( int index, io.netty.example.worldclock.WorldClockProtocol.Location value) { if (locationBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } + checkNotNull(value, "value"); ensureLocationIsMutable(); location_.add(index, value); onChanged(); @@ -2501,9 +2491,7 @@ public final class WorldClockProtocol { * required .io.netty.example.worldclock.DayOfWeek dayOfWeek = 5; */ public Builder setDayOfWeek(io.netty.example.worldclock.WorldClockProtocol.DayOfWeek value) { - if (value == null) { - throw new NullPointerException(); - } + checkNotNull(value, "value"); bitField0_ |= 0x00000008; dayOfWeek_ = value; onChanged(); @@ -3145,9 +3133,7 @@ public final class WorldClockProtocol { public Builder setLocalTime( int index, io.netty.example.worldclock.WorldClockProtocol.LocalTime value) { if (localTimeBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } + checkNotNull(value, "value"); ensureLocalTimeIsMutable(); localTime_.set(index, value); onChanged(); @@ -3175,9 +3161,7 @@ public final class WorldClockProtocol { */ public Builder addLocalTime(io.netty.example.worldclock.WorldClockProtocol.LocalTime value) { if (localTimeBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } + checkNotNull(value, "value"); ensureLocalTimeIsMutable(); localTime_.add(value); onChanged(); @@ -3192,9 +3176,7 @@ public final class WorldClockProtocol { public Builder addLocalTime( int index, io.netty.example.worldclock.WorldClockProtocol.LocalTime value) { if (localTimeBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } + checkNotNull(value, "value"); ensureLocalTimeIsMutable(); localTime_.add(index, value); onChanged();