From 071fa68a3c0186455c804a3fe4cfb89513b807df Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Thu, 9 Jan 2020 11:45:04 -0500 Subject: [PATCH] Misc clean ups. (#200) --- .../client5/http/ConnectExceptionSupport.java | 7 +++---- .../org/apache/hc/client5/http/HttpRoute.java | 3 +-- .../http/entity/DecompressingEntity.java | 3 +-- .../http/entity/mime/FormBodyPart.java | 1 + .../impl/routing/DefaultRoutePlanner.java | 3 +-- .../client5/http/psl/PublicSuffixMatcher.java | 3 +-- .../client5/http/routing/RoutingSupport.java | 19 +++++++++---------- .../http/ssl/ConscryptClientTlsStrategy.java | 3 +-- .../client5/http/ssl/TlsSessionValidator.java | 3 +-- 9 files changed, 19 insertions(+), 26 deletions(-) diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/ConnectExceptionSupport.java b/httpclient5/src/main/java/org/apache/hc/client5/http/ConnectExceptionSupport.java index 49ab3972a..b7b72d80c 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/ConnectExceptionSupport.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/ConnectExceptionSupport.java @@ -74,11 +74,10 @@ public final class ConnectExceptionSupport { final IOException ex = createConnectTimeoutException(cause, namedEndpoint, remoteAddresses); ex.initCause(cause); return ex; - } else { - final IOException ex = createHttpHostConnectException(cause, namedEndpoint, remoteAddresses); - ex.setStackTrace(cause.getStackTrace()); - return ex; } + final IOException ex = createHttpHostConnectException(cause, namedEndpoint, remoteAddresses); + ex.setStackTrace(cause.getStackTrace()); + return ex; } else { return cause; } diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/HttpRoute.java b/httpclient5/src/main/java/org/apache/hc/client5/http/HttpRoute.java index ce3a6be55..665164081 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/HttpRoute.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/HttpRoute.java @@ -213,9 +213,8 @@ public final class HttpRoute implements RouteInfo, Cloneable { Args.check(hop < hopcount, "Hop index exceeds tracked route length"); if (hop < hopcount - 1) { return this.proxyChain.get(hop); - } else { - return this.targetHost; } + return this.targetHost; } @Override diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/entity/DecompressingEntity.java b/httpclient5/src/main/java/org/apache/hc/client5/http/entity/DecompressingEntity.java index 5b1018836..38f51cd21 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/entity/DecompressingEntity.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/entity/DecompressingEntity.java @@ -67,8 +67,7 @@ public class DecompressingEntity extends HttpEntityWrapper { } private InputStream getDecompressingStream() throws IOException { - final InputStream in = super.getContent(); - return new LazyDecompressingInputStream(in, inputStreamFactory); + return new LazyDecompressingInputStream(super.getContent(), inputStreamFactory); } @Override diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/FormBodyPart.java b/httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/FormBodyPart.java index 9f3e9261b..5edb67ce4 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/FormBodyPart.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/FormBodyPart.java @@ -51,6 +51,7 @@ public class FormBodyPart extends MultipartPart { return this.name; } + @Override public void addField(final String name, final String value) { Args.notNull(name, "Field name"); super.addField(name, value); diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/routing/DefaultRoutePlanner.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/routing/DefaultRoutePlanner.java index 547147648..3ee5e070c 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/routing/DefaultRoutePlanner.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/routing/DefaultRoutePlanner.java @@ -77,9 +77,8 @@ public class DefaultRoutePlanner implements HttpRoutePlanner { final boolean secure = target.getSchemeName().equalsIgnoreCase("https"); if (proxy == null) { return new HttpRoute(target, determineLocalAddress(target, context), secure); - } else { - return new HttpRoute(target, determineLocalAddress(proxy, context), proxy, secure); } + return new HttpRoute(target, determineLocalAddress(proxy, context), proxy, secure); } /** diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/psl/PublicSuffixMatcher.java b/httpclient5/src/main/java/org/apache/hc/client5/http/psl/PublicSuffixMatcher.java index bb1fdcd73..628ee78d9 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/psl/PublicSuffixMatcher.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/psl/PublicSuffixMatcher.java @@ -106,9 +106,8 @@ public final class PublicSuffixMatcher { final DomainType domainType = map.get(rule); if (domainType == null) { return false; - } else { - return expectedType == null || domainType.equals(expectedType); } + return expectedType == null || domainType.equals(expectedType); } private boolean hasRule(final String rule, final DomainType expectedType) { diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/routing/RoutingSupport.java b/httpclient5/src/main/java/org/apache/hc/client5/http/routing/RoutingSupport.java index 965a8c713..4205a1923 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/routing/RoutingSupport.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/routing/RoutingSupport.java @@ -51,18 +51,17 @@ public final class RoutingSupport { throw new ProtocolException("Protocol scheme is not specified"); } return new HttpHost(scheme, authority); - } else { - try { - final URI requestURI = request.getUri(); - if (requestURI.isAbsolute()) { - final HttpHost httpHost = URIUtils.extractHost(requestURI); - if (httpHost == null) { - throw new ProtocolException("URI does not specify a valid host name: " + requestURI); - } - return httpHost; + } + try { + final URI requestURI = request.getUri(); + if (requestURI.isAbsolute()) { + final HttpHost httpHost = URIUtils.extractHost(requestURI); + if (httpHost == null) { + throw new ProtocolException("URI does not specify a valid host name: " + requestURI); } - } catch (final URISyntaxException ignore) { + return httpHost; } + } catch (final URISyntaxException ignore) { } return null; } diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/ConscryptClientTlsStrategy.java b/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/ConscryptClientTlsStrategy.java index 9ec8dbf75..e446b084e 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/ConscryptClientTlsStrategy.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/ConscryptClientTlsStrategy.java @@ -101,9 +101,8 @@ public class ConscryptClientTlsStrategy extends AbstractClientTlsStrategy { TlsDetails createTlsDetails(final SSLEngine sslEngine) { if (Conscrypt.isConscrypt(sslEngine)) { return new TlsDetails(sslEngine.getSession(), Conscrypt.getApplicationProtocol(sslEngine)); - } else { - return null; } + return null; } public static boolean isSupported() { diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/TlsSessionValidator.java b/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/TlsSessionValidator.java index b2d49aafc..4611bab1d 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/TlsSessionValidator.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/TlsSessionValidator.java @@ -117,9 +117,8 @@ final class TlsSessionValidator { final ProtocolVersion tls = TLS.parse(sslsession.getProtocol()); if (tls.greaterEquals(TLS.V_1_3.version)) { return; - } else { - throw ex; } + throw ex; } catch (final ParseException ex2) { throw ex; }