From 8c840c918b303505a8158ad52ffef8615e3f4aab Mon Sep 17 00:00:00 2001 From: "Gary D. Gregory" Date: Wed, 27 Jan 2016 08:14:03 +0000 Subject: [PATCH] Statement unnecessarily nested within else clause. git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1726950 13f79535-47bb-0310-9956-ffa450edef68 --- .../http/impl/auth/AuthChallengeParser.java | 15 +++---- .../http/impl/auth/BasicAuthCache.java | 6 +-- .../client5/http/impl/auth/BasicScheme.java | 7 ++- .../client5/http/impl/auth/DigestScheme.java | 13 ++---- .../http/impl/auth/HttpAuthenticator.java | 43 ++++++++----------- .../hc/client5/http/impl/auth/NTLMScheme.java | 3 +- 6 files changed, 36 insertions(+), 51 deletions(-) diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/AuthChallengeParser.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/AuthChallengeParser.java index 48468d5aa..83203608c 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/AuthChallengeParser.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/AuthChallengeParser.java @@ -109,15 +109,14 @@ public class AuthChallengeParser { } } return new AuthChallenge(scheme, null, params.size() > 0 ? params : null); - } else { - if (params.size() == 1) { - final NameValuePair nvp = params.get(0); - if (nvp.getValue() == null) { - return new AuthChallenge(nvp.getName(), null, null); - } - } - throw new ParseException("Malformed auth challenge"); } + if (params.size() == 1) { + final NameValuePair nvp = params.get(0); + if (nvp.getValue() == null) { + return new AuthChallenge(nvp.getName(), null, null); + } + } + throw new ParseException("Malformed auth challenge"); } } diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/BasicAuthCache.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/BasicAuthCache.java index 6e3d8096b..fe82e1af8 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/BasicAuthCache.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/BasicAuthCache.java @@ -89,9 +89,8 @@ public class BasicAuthCache implements AuthCache { return host; } return new HttpHost(host.getHostName(), port, host.getSchemeName()); - } else { - return host; } + return host; } @Override @@ -141,9 +140,8 @@ public class BasicAuthCache implements AuthCache { } return null; } - } else { - return null; } + return null; } @Override diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/BasicScheme.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/BasicScheme.java index 3bd757c76..d09cf3923 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/BasicScheme.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/BasicScheme.java @@ -145,11 +145,10 @@ public class BasicScheme implements AuthScheme, Serializable { this.username = credentials.getUserPrincipal().getName(); this.password = credentials.getPassword(); return true; - } else { - this.username = null; - this.password = null; - return false; } + this.username = null; + this.password = null; + return false; } @Override diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/DigestScheme.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/DigestScheme.java index d8f34a00e..fc1f95682 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/DigestScheme.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/DigestScheme.java @@ -160,11 +160,7 @@ public class DigestScheme implements AuthScheme, Serializable { @Override public boolean isChallengeComplete() { final String s = this.paramMap.get("stale"); - if ("true".equalsIgnoreCase(s)) { - return false; - } else { - return this.complete; - } + return "true".equalsIgnoreCase(s) ? false : this.complete; } @Override @@ -181,11 +177,10 @@ public class DigestScheme implements AuthScheme, Serializable { this.username = credentials.getUserPrincipal().getName(); this.password = credentials.getPassword(); return true; - } else { - this.username = null; - this.password = null; - return false; } + this.username = null; + this.password = null; + return false; } @Override diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/HttpAuthenticator.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/HttpAuthenticator.java index 11a0a4bad..b41a1d4cd 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/HttpAuthenticator.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/HttpAuthenticator.java @@ -105,21 +105,20 @@ public class HttpAuthenticator { clearCache(host, clientContext); } return true; - } else { - switch (authExchange.getState()) { - case CHALLENGED: - case HANDSHAKE: - this.log.debug("Authentication succeeded"); - authExchange.setState(AuthExchange.State.SUCCESS); - updateCache(host, authExchange.getAuthScheme(), clientContext); - break; - case SUCCESS: - break; - default: - authExchange.setState(AuthExchange.State.UNCHALLENGED); - } - return false; } + switch (authExchange.getState()) { + case CHALLENGED: + case HANDSHAKE: + this.log.debug("Authentication succeeded"); + authExchange.setState(AuthExchange.State.SUCCESS); + updateCache(host, authExchange.getAuthScheme(), clientContext); + break; + case SUCCESS: + break; + default: + authExchange.setState(AuthExchange.State.UNCHALLENGED); + } + return false; } public boolean prepareAuthResponse( @@ -210,14 +209,12 @@ public class HttpAuthenticator { authExchange.reset(); authExchange.setState(AuthExchange.State.FAILURE); return false; - } else { - authExchange.setState(AuthExchange.State.HANDSHAKE); - return true; } - } else { - authExchange.reset(); - // Retry authentication with a different scheme + authExchange.setState(AuthExchange.State.HANDSHAKE); + return true; } + authExchange.reset(); + // Retry authentication with a different scheme } } @@ -251,9 +248,8 @@ public class HttpAuthenticator { authExchange.setState(AuthExchange.State.CHALLENGED); authExchange.setOptions(authOptions); return true; - } else { - return false; } + return false; } public void addAuthResponse( @@ -299,9 +295,8 @@ public class HttpAuthenticator { } } return; - } else { - Asserts.notNull(authScheme, "AuthScheme"); } + Asserts.notNull(authScheme, "AuthScheme"); default: } if (authScheme != null) { diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/NTLMScheme.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/NTLMScheme.java index d9227260b..f67f608f7 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/NTLMScheme.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/NTLMScheme.java @@ -133,9 +133,8 @@ public class NTLMScheme implements AuthScheme { if (credentials instanceof NTCredentials) { this.credentials = (NTCredentials) credentials; return true; - } else { - return false; } + return false; } @Override