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 in microbench and resolver-dns Fixes #11170
This commit is contained in:
parent
c1a04297e7
commit
0e8f5c5f7c
@ -48,6 +48,7 @@ import static io.netty.handler.codec.http2.Http2CodecUtil.MAX_UNSIGNED_BYTE;
|
||||
import static io.netty.handler.codec.http2.Http2CodecUtil.verifyPadding;
|
||||
import static io.netty.handler.codec.http2.Http2CodecUtil.writeFrameHeaderInternal;
|
||||
import static io.netty.handler.codec.http2.Http2FrameTypes.DATA;
|
||||
import static io.netty.util.internal.ObjectUtil.checkPositive;
|
||||
import static java.lang.Math.max;
|
||||
import static java.lang.Math.min;
|
||||
|
||||
@ -124,7 +125,7 @@ public class Http2FrameWriterDataBenchmark extends AbstractMicrobenchmark {
|
||||
boolean needToReleaseHeaders = true;
|
||||
boolean needToReleaseData = true;
|
||||
try {
|
||||
verifyStreamId(streamId, "Stream ID");
|
||||
checkPositive(streamId, "streamId");
|
||||
verifyPadding(padding);
|
||||
|
||||
boolean lastFrame;
|
||||
@ -175,12 +176,6 @@ public class Http2FrameWriterDataBenchmark extends AbstractMicrobenchmark {
|
||||
return promiseAggregator.doneAllocatingPromises();
|
||||
}
|
||||
|
||||
private static void verifyStreamId(int streamId, String argumentName) {
|
||||
if (streamId <= 0) {
|
||||
throw new IllegalArgumentException(argumentName + " must be > 0");
|
||||
}
|
||||
}
|
||||
|
||||
private static int paddingBytes(int padding) {
|
||||
// The padding parameter contains the 1 byte pad length field as well as the trailing padding bytes.
|
||||
// Subtract 1, so to only get the number of padding bytes that need to be appended to the end of a frame.
|
||||
|
@ -17,6 +17,7 @@
|
||||
package io.netty.resolver.dns;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
import static io.netty.util.internal.ObjectUtil.checkNonEmpty;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.ArrayList;
|
||||
@ -176,11 +177,7 @@ public abstract class DnsServerAddresses {
|
||||
list.add(a);
|
||||
}
|
||||
|
||||
if (list.isEmpty()) {
|
||||
throw new IllegalArgumentException("empty addresses");
|
||||
}
|
||||
|
||||
return list;
|
||||
return checkNonEmpty(list, "list");
|
||||
}
|
||||
|
||||
private static List<InetSocketAddress> sanitize(InetSocketAddress[] addresses) {
|
||||
|
Loading…
Reference in New Issue
Block a user