diff --git a/client/src/main/java/org/asynchttpclient/AsyncCompletionHandlerBase.java b/client/src/main/java/org/asynchttpclient/AsyncCompletionHandlerBase.java index 8ad58eff6..25fc9da18 100644 --- a/client/src/main/java/org/asynchttpclient/AsyncCompletionHandlerBase.java +++ b/client/src/main/java/org/asynchttpclient/AsyncCompletionHandlerBase.java @@ -23,6 +23,7 @@ * Simple {@link AsyncHandler} of type {@link Response} */ public class AsyncCompletionHandlerBase extends AsyncCompletionHandler { + @Override public @Nullable Response onCompleted(@Nullable Response response) throws Exception { return response; diff --git a/client/src/main/java/org/asynchttpclient/DefaultAsyncHttpClient.java b/client/src/main/java/org/asynchttpclient/DefaultAsyncHttpClient.java index 22eb92068..fb5dad6ff 100644 --- a/client/src/main/java/org/asynchttpclient/DefaultAsyncHttpClient.java +++ b/client/src/main/java/org/asynchttpclient/DefaultAsyncHttpClient.java @@ -40,7 +40,7 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Predicate; -import static org.asynchttpclient.util.Assertions.assertNotNull; +import static java.util.Objects.requireNonNull; import static org.asynchttpclient.util.HttpConstants.Methods.CONNECT; import static org.asynchttpclient.util.HttpConstants.Methods.DELETE; import static org.asynchttpclient.util.HttpConstants.Methods.GET; @@ -294,7 +294,7 @@ private ListenableFuture execute(Request request, final AsyncHandler a private FilterContext preProcessRequest(FilterContext fc) throws FilterException { for (RequestFilter asyncFilter : config.getRequestFilters()) { fc = asyncFilter.filter(fc); - assertNotNull(fc, "filterContext"); + requireNonNull(fc, "filterContext"); } Request request = fc.getRequest(); diff --git a/client/src/main/java/org/asynchttpclient/Realm.java b/client/src/main/java/org/asynchttpclient/Realm.java index 2006bd8b8..c6b70a7de 100644 --- a/client/src/main/java/org/asynchttpclient/Realm.java +++ b/client/src/main/java/org/asynchttpclient/Realm.java @@ -29,7 +29,7 @@ import static java.nio.charset.StandardCharsets.ISO_8859_1; import static java.nio.charset.StandardCharsets.UTF_8; -import static org.asynchttpclient.util.Assertions.assertNotNull; +import static java.util.Objects.requireNonNull; import static org.asynchttpclient.util.HttpConstants.Methods.GET; import static org.asynchttpclient.util.MessageDigestUtils.pooledMd5MessageDigest; import static org.asynchttpclient.util.MiscUtils.isNonEmpty; @@ -92,7 +92,7 @@ private Realm(@Nullable AuthScheme scheme, @Nullable Map customLoginConfig, @Nullable String loginContextName) { - this.scheme = assertNotNull(scheme, "scheme"); + this.scheme = requireNonNull(scheme, "scheme"); this.principal = principal; this.password = password; this.realmName = realmName; diff --git a/client/src/main/java/org/asynchttpclient/channel/NoopChannelPool.java b/client/src/main/java/org/asynchttpclient/channel/NoopChannelPool.java index 8ea39e6bd..3a5b2e93d 100644 --- a/client/src/main/java/org/asynchttpclient/channel/NoopChannelPool.java +++ b/client/src/main/java/org/asynchttpclient/channel/NoopChannelPool.java @@ -22,38 +22,69 @@ import java.util.Map; import java.util.function.Predicate; +/** + * A {@link ChannelPool} implementation that doesn't pool anything. + */ public enum NoopChannelPool implements ChannelPool { INSTANCE; + /** + * + * @return always false since this is a {@link NoopChannelPool} + */ @Override public boolean offer(Channel channel, Object partitionKey) { return false; } + /** + * + * @return always null since this is a {@link NoopChannelPool} + */ @Override public @Nullable Channel poll(Object partitionKey) { return null; } + /** + * + * @return always false since this is a {@link NoopChannelPool} + */ @Override public boolean removeAll(Channel channel) { return false; } + /** + * + * @return always true since this is a {@link NoopChannelPool} + */ @Override public boolean isOpen() { return true; } + /** + * + * Does nothing since this is a {@link NoopChannelPool} + */ @Override public void destroy() { } + /** + * + * Does nothing since this is a {@link NoopChannelPool} + */ @Override public void flushPartitions(Predicate predicate) { } + /** + * + * @return always {@link Collections#emptyMap()} since this is a {@link NoopChannelPool} + */ @Override public Map getIdleChannelCountPerHost() { return Collections.emptyMap(); diff --git a/client/src/main/java/org/asynchttpclient/config/AsyncHttpClientConfigHelper.java b/client/src/main/java/org/asynchttpclient/config/AsyncHttpClientConfigHelper.java index 3922a6d60..7bb87afb3 100644 --- a/client/src/main/java/org/asynchttpclient/config/AsyncHttpClientConfigHelper.java +++ b/client/src/main/java/org/asynchttpclient/config/AsyncHttpClientConfigHelper.java @@ -64,18 +64,29 @@ public void reload() { propsCache.clear(); } + /** + * Parse a property file. + * + * @param file the file to parse + * @param required if true, the file must be present + * @return the parsed properties + * @throws RuntimeException if the file is required and not present or if the file can't be parsed + */ private Properties parsePropertiesFile(String file, boolean required) { Properties props = new Properties(); - InputStream is = getClass().getResourceAsStream(file); - if (is != null) { - try { - props.load(is); - } catch (IOException e) { - throw new IllegalArgumentException("Can't parse config file " + file, e); + try (InputStream is = getClass().getResourceAsStream(file)) { + if (is != null) { + try { + props.load(is); + } catch (IOException e) { + throw new IllegalArgumentException("Can't parse config file " + file, e); + } + } else if (required) { + throw new IllegalArgumentException("Can't locate config file " + file); } - } else if (required) { - throw new IllegalArgumentException("Can't locate config file " + file); + } catch (IOException e) { + throw new RuntimeException(e); } return props; diff --git a/client/src/main/java/org/asynchttpclient/cookie/ThreadSafeCookieStore.java b/client/src/main/java/org/asynchttpclient/cookie/ThreadSafeCookieStore.java index 44cb4e260..35a620e31 100644 --- a/client/src/main/java/org/asynchttpclient/cookie/ThreadSafeCookieStore.java +++ b/client/src/main/java/org/asynchttpclient/cookie/ThreadSafeCookieStore.java @@ -17,7 +17,6 @@ import io.netty.handler.codec.http.cookie.Cookie; import org.asynchttpclient.uri.Uri; -import org.asynchttpclient.util.Assertions; import org.asynchttpclient.util.MiscUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -34,6 +33,8 @@ import java.util.function.Predicate; import java.util.stream.Collectors; +import static java.util.Objects.requireNonNull; + public final class ThreadSafeCookieStore implements CookieStore { private final Map> cookieJar = new ConcurrentHashMap<>(); @@ -88,7 +89,6 @@ public void evictExpired() { removeExpired(); } - @Override public int incrementAndGet() { return counter.incrementAndGet(); @@ -226,8 +226,11 @@ private List getStoredCookies(String domain, String path, boolean secure private void removeExpired() { final boolean[] removed = {false}; - cookieJar.values().forEach(cookieMap -> removed[0] |= cookieMap.entrySet().removeIf( - v -> hasCookieExpired(v.getValue().cookie, v.getValue().createdAt))); + + cookieJar.values() + .forEach(cookieMap -> removed[0] |= cookieMap.entrySet() + .removeIf(v -> hasCookieExpired(v.getValue().cookie, v.getValue().createdAt))); + if (removed[0]) { cookieJar.entrySet().removeIf(entry -> entry.getValue() == null || entry.getValue().isEmpty()); } @@ -243,11 +246,12 @@ private static class CookieKey implements Comparable { } @Override - public int compareTo(@NotNull CookieKey o) { - Assertions.assertNotNull(o, "Parameter can't be null"); + public int compareTo(@NotNull CookieKey cookieKey) { + requireNonNull(cookieKey, "Parameter can't be null"); + int result; - if ((result = name.compareTo(o.name)) == 0) { - result = path.compareTo(o.path); + if ((result = name.compareTo(cookieKey.name)) == 0) { + result = path.compareTo(cookieKey.path); } return result; } diff --git a/client/src/main/java/org/asynchttpclient/exception/ChannelClosedException.java b/client/src/main/java/org/asynchttpclient/exception/ChannelClosedException.java index 3d1101291..4b63997aa 100644 --- a/client/src/main/java/org/asynchttpclient/exception/ChannelClosedException.java +++ b/client/src/main/java/org/asynchttpclient/exception/ChannelClosedException.java @@ -19,7 +19,11 @@ import static org.asynchttpclient.util.ThrowableUtil.unknownStackTrace; +/** + * This exception is thrown when a channel is closed. + */ public final class ChannelClosedException extends IOException { + private static final long serialVersionUID = -2528693697240456658L; public static final ChannelClosedException INSTANCE = unknownStackTrace(new ChannelClosedException(), ChannelClosedException.class, "INSTANCE"); diff --git a/client/src/main/java/org/asynchttpclient/exception/PoolAlreadyClosedException.java b/client/src/main/java/org/asynchttpclient/exception/PoolAlreadyClosedException.java index d832bc40a..d66c3b76a 100644 --- a/client/src/main/java/org/asynchttpclient/exception/PoolAlreadyClosedException.java +++ b/client/src/main/java/org/asynchttpclient/exception/PoolAlreadyClosedException.java @@ -19,7 +19,11 @@ import static org.asynchttpclient.util.ThrowableUtil.unknownStackTrace; +/** + * This exception is thrown when a channel pool is already closed. + */ public class PoolAlreadyClosedException extends IOException { + private static final long serialVersionUID = -3883404852005245296L; public static final PoolAlreadyClosedException INSTANCE = unknownStackTrace(new PoolAlreadyClosedException(), PoolAlreadyClosedException.class, "INSTANCE"); diff --git a/client/src/main/java/org/asynchttpclient/exception/RemotelyClosedException.java b/client/src/main/java/org/asynchttpclient/exception/RemotelyClosedException.java index 8b8165589..2b1977a6f 100644 --- a/client/src/main/java/org/asynchttpclient/exception/RemotelyClosedException.java +++ b/client/src/main/java/org/asynchttpclient/exception/RemotelyClosedException.java @@ -19,7 +19,11 @@ import static org.asynchttpclient.util.ThrowableUtil.unknownStackTrace; +/** + * This exception is thrown when a channel is closed by remote host. + */ public final class RemotelyClosedException extends IOException { + private static final long serialVersionUID = 5634105738124356785L; public static final RemotelyClosedException INSTANCE = unknownStackTrace(new RemotelyClosedException(), RemotelyClosedException.class, "INSTANCE"); diff --git a/client/src/main/java/org/asynchttpclient/exception/TooManyConnectionsException.java b/client/src/main/java/org/asynchttpclient/exception/TooManyConnectionsException.java index 2a0add003..6797c68c7 100644 --- a/client/src/main/java/org/asynchttpclient/exception/TooManyConnectionsException.java +++ b/client/src/main/java/org/asynchttpclient/exception/TooManyConnectionsException.java @@ -17,6 +17,9 @@ import java.io.IOException; +/** + * This exception is thrown when too many connections are opened. + */ public class TooManyConnectionsException extends IOException { private static final long serialVersionUID = 8645586459539317237L; diff --git a/client/src/main/java/org/asynchttpclient/exception/TooManyConnectionsPerHostException.java b/client/src/main/java/org/asynchttpclient/exception/TooManyConnectionsPerHostException.java index 47f5be7e2..e7959bb37 100644 --- a/client/src/main/java/org/asynchttpclient/exception/TooManyConnectionsPerHostException.java +++ b/client/src/main/java/org/asynchttpclient/exception/TooManyConnectionsPerHostException.java @@ -17,6 +17,9 @@ import java.io.IOException; +/** + * This exception is thrown when too many connections are opened to a remote host. + */ public class TooManyConnectionsPerHostException extends IOException { private static final long serialVersionUID = 5702859695179937503L; diff --git a/client/src/main/java/org/asynchttpclient/netty/channel/ChannelState.java b/client/src/main/java/org/asynchttpclient/netty/channel/ChannelState.java index 6dd824466..1b550983e 100644 --- a/client/src/main/java/org/asynchttpclient/netty/channel/ChannelState.java +++ b/client/src/main/java/org/asynchttpclient/netty/channel/ChannelState.java @@ -16,5 +16,23 @@ package org.asynchttpclient.netty.channel; public enum ChannelState { - NEW, POOLED, RECONNECTED, CLOSED, + /** + * The channel is new + */ + NEW, + + /** + * The channel is open and pooled + */ + POOLED, + + /** + * The channel is reconnected + */ + RECONNECTED, + + /** + * The channel is closed + */ + CLOSED, } diff --git a/client/src/main/java/org/asynchttpclient/netty/channel/DefaultChannelPool.java b/client/src/main/java/org/asynchttpclient/netty/channel/DefaultChannelPool.java index 2c1916faf..0ae2f68f7 100755 --- a/client/src/main/java/org/asynchttpclient/netty/channel/DefaultChannelPool.java +++ b/client/src/main/java/org/asynchttpclient/netty/channel/DefaultChannelPool.java @@ -42,7 +42,7 @@ import java.util.function.Predicate; import java.util.stream.Collectors; -import static org.asynchttpclient.util.Assertions.assertNotNull; +import static java.util.Objects.requireNonNull; import static org.asynchttpclient.util.DateUtils.unpreciseMillisTime; /** @@ -260,7 +260,7 @@ private static final class IdleChannel { private volatile int owned; IdleChannel(Channel channel, long start) { - this.channel = assertNotNull(channel, "channel"); + this.channel = requireNonNull(channel, "channel"); this.start = start; } diff --git a/client/src/main/java/org/asynchttpclient/netty/handler/intercept/ResponseFiltersInterceptor.java b/client/src/main/java/org/asynchttpclient/netty/handler/intercept/ResponseFiltersInterceptor.java index d3f33d49f..19b41f502 100644 --- a/client/src/main/java/org/asynchttpclient/netty/handler/intercept/ResponseFiltersInterceptor.java +++ b/client/src/main/java/org/asynchttpclient/netty/handler/intercept/ResponseFiltersInterceptor.java @@ -50,7 +50,7 @@ public boolean exitAfterProcessingFilters(Channel channel, try { fc = asyncFilter.filter(fc); // FIXME Is it worth protecting against this? -// assertNotNull(fc, "filterContext"); +// requireNonNull(fc, "filterContext"); } catch (FilterException fe) { requestSender.abort(channel, future, fe); } diff --git a/client/src/main/java/org/asynchttpclient/netty/request/NettyRequestSender.java b/client/src/main/java/org/asynchttpclient/netty/request/NettyRequestSender.java index bb3628123..2c0314325 100755 --- a/client/src/main/java/org/asynchttpclient/netty/request/NettyRequestSender.java +++ b/client/src/main/java/org/asynchttpclient/netty/request/NettyRequestSender.java @@ -67,7 +67,7 @@ import static io.netty.handler.codec.http.HttpHeaderNames.EXPECT; import static java.util.Collections.singletonList; -import static org.asynchttpclient.util.Assertions.assertNotNull; +import static java.util.Objects.requireNonNull; import static org.asynchttpclient.util.AuthenticatorUtils.perConnectionAuthorizationHeader; import static org.asynchttpclient.util.AuthenticatorUtils.perConnectionProxyAuthorizationHeader; import static org.asynchttpclient.util.HttpConstants.Methods.CONNECT; @@ -506,7 +506,7 @@ public boolean applyIoExceptionFiltersAndReplayRequest(NettyResponseFuture fu for (IOExceptionFilter asyncFilter : config.getIoExceptionFilters()) { try { fc = asyncFilter.filter(fc); - assertNotNull(fc, "filterContext"); + requireNonNull(fc, "filterContext"); } catch (FilterException efe) { abort(channel, future, efe); } diff --git a/client/src/main/java/org/asynchttpclient/netty/request/body/BodyChunkedInput.java b/client/src/main/java/org/asynchttpclient/netty/request/body/BodyChunkedInput.java index e6dbd8c7e..cd0434146 100755 --- a/client/src/main/java/org/asynchttpclient/netty/request/body/BodyChunkedInput.java +++ b/client/src/main/java/org/asynchttpclient/netty/request/body/BodyChunkedInput.java @@ -21,7 +21,7 @@ import io.netty.handler.stream.ChunkedInput; import org.asynchttpclient.request.body.Body; -import static org.asynchttpclient.util.Assertions.assertNotNull; +import static java.util.Objects.requireNonNull; /** * Adapts a {@link Body} to Netty's {@link ChunkedInput}. @@ -37,7 +37,7 @@ public class BodyChunkedInput implements ChunkedInput { private long progress; BodyChunkedInput(Body body) { - this.body = assertNotNull(body, "body"); + this.body = requireNonNull(body, "body"); contentLength = body.getContentLength(); if (contentLength <= 0) { chunkSize = DEFAULT_CHUNK_SIZE; diff --git a/client/src/main/java/org/asynchttpclient/netty/request/body/BodyFileRegion.java b/client/src/main/java/org/asynchttpclient/netty/request/body/BodyFileRegion.java index 5542f4dd5..9326d717d 100755 --- a/client/src/main/java/org/asynchttpclient/netty/request/body/BodyFileRegion.java +++ b/client/src/main/java/org/asynchttpclient/netty/request/body/BodyFileRegion.java @@ -22,7 +22,7 @@ import java.io.IOException; import java.nio.channels.WritableByteChannel; -import static org.asynchttpclient.util.Assertions.assertNotNull; +import static java.util.Objects.requireNonNull; import static org.asynchttpclient.util.MiscUtils.closeSilently; /** @@ -34,7 +34,7 @@ class BodyFileRegion extends AbstractReferenceCounted implements FileRegion { private long transferred; BodyFileRegion(RandomAccessBody body) { - this.body = assertNotNull(body, "body"); + this.body = requireNonNull(body, "body"); } @Override diff --git a/client/src/main/java/org/asynchttpclient/proxy/ProxyServer.java b/client/src/main/java/org/asynchttpclient/proxy/ProxyServer.java index c7d1d6106..9cb33362c 100644 --- a/client/src/main/java/org/asynchttpclient/proxy/ProxyServer.java +++ b/client/src/main/java/org/asynchttpclient/proxy/ProxyServer.java @@ -26,7 +26,7 @@ import java.util.List; import java.util.function.Function; -import static org.asynchttpclient.util.Assertions.assertNotNull; +import static java.util.Objects.requireNonNull; import static org.asynchttpclient.util.MiscUtils.isNonEmpty; /** @@ -100,7 +100,7 @@ public ProxyType getProxyType() { * Properties */ public boolean isIgnoredForHost(String hostname) { - assertNotNull(hostname, "hostname"); + requireNonNull(hostname, "hostname"); if (isNonEmpty(nonProxyHosts)) { for (String nonProxyHost : nonProxyHosts) { if (matchNonProxyHost(hostname, nonProxyHost)) { diff --git a/client/src/main/java/org/asynchttpclient/request/body/generator/FileBodyGenerator.java b/client/src/main/java/org/asynchttpclient/request/body/generator/FileBodyGenerator.java index ae8869486..82bc02111 100644 --- a/client/src/main/java/org/asynchttpclient/request/body/generator/FileBodyGenerator.java +++ b/client/src/main/java/org/asynchttpclient/request/body/generator/FileBodyGenerator.java @@ -16,7 +16,7 @@ import java.io.File; -import static org.asynchttpclient.util.Assertions.assertNotNull; +import static java.util.Objects.requireNonNull; /** * Creates a request body from the contents of a file. @@ -32,7 +32,7 @@ public FileBodyGenerator(File file) { } public FileBodyGenerator(File file, long regionSeek, long regionLength) { - this.file = assertNotNull(file, "file"); + this.file = requireNonNull(file, "file"); this.regionLength = regionLength; this.regionSeek = regionSeek; } diff --git a/client/src/main/java/org/asynchttpclient/request/body/multipart/ByteArrayPart.java b/client/src/main/java/org/asynchttpclient/request/body/multipart/ByteArrayPart.java index 6ef4b8d79..97ed6cc61 100644 --- a/client/src/main/java/org/asynchttpclient/request/body/multipart/ByteArrayPart.java +++ b/client/src/main/java/org/asynchttpclient/request/body/multipart/ByteArrayPart.java @@ -17,7 +17,7 @@ import java.nio.charset.Charset; -import static org.asynchttpclient.util.Assertions.assertNotNull; +import static java.util.Objects.requireNonNull; public class ByteArrayPart extends FileLikePart { @@ -45,7 +45,7 @@ public ByteArrayPart(String name, byte[] bytes, String contentType, Charset char public ByteArrayPart(String name, byte[] bytes, String contentType, Charset charset, String fileName, String contentId, String transferEncoding) { super(name, contentType, charset, fileName, contentId, transferEncoding); - this.bytes = assertNotNull(bytes, "bytes"); + this.bytes = requireNonNull(bytes, "bytes"); } public byte[] getBytes() { diff --git a/client/src/main/java/org/asynchttpclient/request/body/multipart/InputStreamPart.java b/client/src/main/java/org/asynchttpclient/request/body/multipart/InputStreamPart.java index 048105973..aa14c979a 100644 --- a/client/src/main/java/org/asynchttpclient/request/body/multipart/InputStreamPart.java +++ b/client/src/main/java/org/asynchttpclient/request/body/multipart/InputStreamPart.java @@ -18,7 +18,7 @@ import java.io.InputStream; import java.nio.charset.Charset; -import static org.asynchttpclient.util.Assertions.assertNotNull; +import static java.util.Objects.requireNonNull; public class InputStreamPart extends FileLikePart { @@ -48,7 +48,7 @@ public InputStreamPart(String name, InputStream inputStream, String fileName, lo public InputStreamPart(String name, InputStream inputStream, String fileName, long contentLength, String contentType, Charset charset, String contentId, String transferEncoding) { super(name, contentType, charset, fileName, contentId, transferEncoding); - this.inputStream = assertNotNull(inputStream, "inputStream"); + this.inputStream = requireNonNull(inputStream, "inputStream"); this.contentLength = contentLength; } diff --git a/client/src/main/java/org/asynchttpclient/request/body/multipart/MultipartBody.java b/client/src/main/java/org/asynchttpclient/request/body/multipart/MultipartBody.java index 4100fc128..a1fbb6087 100644 --- a/client/src/main/java/org/asynchttpclient/request/body/multipart/MultipartBody.java +++ b/client/src/main/java/org/asynchttpclient/request/body/multipart/MultipartBody.java @@ -28,7 +28,7 @@ import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; -import static org.asynchttpclient.util.Assertions.assertNotNull; +import static java.util.Objects.requireNonNull; import static org.asynchttpclient.util.MiscUtils.closeSilently; public class MultipartBody implements RandomAccessBody { @@ -46,7 +46,7 @@ public class MultipartBody implements RandomAccessBody { public MultipartBody(List> parts, String contentType, byte[] boundary) { this.boundary = boundary; this.contentType = contentType; - this.parts = assertNotNull(parts, "parts"); + this.parts = requireNonNull(parts, "parts"); contentLength = computeContentLength(); } diff --git a/client/src/main/java/org/asynchttpclient/request/body/multipart/MultipartUtils.java b/client/src/main/java/org/asynchttpclient/request/body/multipart/MultipartUtils.java index 8f55fa2ae..eb7314f4b 100644 --- a/client/src/main/java/org/asynchttpclient/request/body/multipart/MultipartUtils.java +++ b/client/src/main/java/org/asynchttpclient/request/body/multipart/MultipartUtils.java @@ -29,7 +29,7 @@ import static io.netty.handler.codec.http.HttpHeaderNames.CONTENT_TYPE; import static java.nio.charset.StandardCharsets.US_ASCII; -import static org.asynchttpclient.util.Assertions.assertNotNull; +import static java.util.Objects.requireNonNull; import static org.asynchttpclient.util.HttpUtils.computeMultipartBoundary; import static org.asynchttpclient.util.HttpUtils.patchContentTypeWithBoundaryAttribute; import static org.asynchttpclient.util.MiscUtils.isNonEmpty; @@ -48,7 +48,7 @@ private MultipartUtils() { * @return a MultipartBody */ public static MultipartBody newMultipartBody(List parts, HttpHeaders requestHeaders) { - assertNotNull(parts, "parts"); + requireNonNull(parts, "parts"); byte[] boundary; String contentType; diff --git a/client/src/main/java/org/asynchttpclient/request/body/multipart/StringPart.java b/client/src/main/java/org/asynchttpclient/request/body/multipart/StringPart.java index 4f853bfb9..2427913ea 100644 --- a/client/src/main/java/org/asynchttpclient/request/body/multipart/StringPart.java +++ b/client/src/main/java/org/asynchttpclient/request/body/multipart/StringPart.java @@ -18,7 +18,7 @@ import java.nio.charset.Charset; import static java.nio.charset.StandardCharsets.UTF_8; -import static org.asynchttpclient.util.Assertions.assertNotNull; +import static java.util.Objects.requireNonNull; import static org.asynchttpclient.util.MiscUtils.withDefault; public class StringPart extends PartBase { @@ -51,7 +51,7 @@ public StringPart(String name, String value, String contentType, Charset charset public StringPart(String name, String value, String contentType, Charset charset, String contentId, String transferEncoding) { super(name, contentType, charsetOrDefault(charset), contentId, transferEncoding); - assertNotNull(value, "value"); + requireNonNull(value, "value"); // See RFC 2048, 2.8. "8bit Data" if (value.indexOf(0) != -1) { diff --git a/client/src/main/java/org/asynchttpclient/uri/UriParser.java b/client/src/main/java/org/asynchttpclient/uri/UriParser.java index ae347277e..40c195630 100644 --- a/client/src/main/java/org/asynchttpclient/uri/UriParser.java +++ b/client/src/main/java/org/asynchttpclient/uri/UriParser.java @@ -17,7 +17,7 @@ import org.jetbrains.annotations.Nullable; -import static org.asynchttpclient.util.Assertions.assertNotNull; +import static java.util.Objects.requireNonNull; import static org.asynchttpclient.util.MiscUtils.isNonEmpty; final class UriParser { @@ -369,7 +369,7 @@ private void parse(@Nullable Uri context) { } public static UriParser parse(@Nullable Uri context, final String originalUrl) { - assertNotNull(originalUrl, "originalUrl"); + requireNonNull(originalUrl, "originalUrl"); final UriParser parser = new UriParser(originalUrl); parser.parse(context); return parser; diff --git a/client/src/main/java/org/asynchttpclient/util/Assertions.java b/client/src/main/java/org/asynchttpclient/util/Assertions.java index 5a5f29c06..0b2e38a7c 100644 --- a/client/src/main/java/org/asynchttpclient/util/Assertions.java +++ b/client/src/main/java/org/asynchttpclient/util/Assertions.java @@ -18,23 +18,16 @@ import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.Nullable; +import static java.util.Objects.requireNonNull; + public final class Assertions { private Assertions() { } - @Contract(value = "null, _ -> fail", pure = true) - public static T assertNotNull(@Nullable T value, String name) { - if (value == null) { - throw new NullPointerException(name); - } - return value; - - } - @Contract(value = "null, _ -> fail", pure = true) public static String assertNotEmpty(@Nullable String value, String name) { - assertNotNull(value, name); + requireNonNull(value, name); if (value.length() == 0) { throw new IllegalArgumentException("empty " + name); }