Simplify conditions and avoid extra checks.
Inline return variables.
diff --git a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/HttpCacheEntryMatcher.java b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/HttpCacheEntryMatcher.java
index 9f1f06f..d5646c8 100644
--- a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/HttpCacheEntryMatcher.java
+++ b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/HttpCacheEntryMatcher.java
@@ -84,10 +84,7 @@
final byte[] expectedContent = expectedResource != null ? expectedResource.get() : null;
final Resource otherResource = otherValue.getResource();
final byte[] otherContent = otherResource != null ? otherResource.get() : null;
- if (!Arrays.equals(expectedContent, otherContent)) {
- return false;
- }
- return true;
+ return Arrays.equals(expectedContent, otherContent);
} catch (final ResourceIOException ex) {
throw new RuntimeException(ex);
}
diff --git a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/HttpTestUtils.java b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/HttpTestUtils.java
index 9815aab..b87e066 100644
--- a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/HttpTestUtils.java
+++ b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/HttpTestUtils.java
@@ -258,9 +258,8 @@
public static HttpCacheEntry makeCacheEntry(final Date requestDate,
final Date responseDate, final Header[] headers, final byte[] bytes) {
- final Map<String,String> variantMap = null;
return makeCacheEntry(requestDate, responseDate, headers, bytes,
- variantMap);
+ null);
}
public static HttpCacheEntry makeCacheEntry(final Map<String,String> variantMap) {
diff --git a/httpclient5-win/src/main/java/org/apache/hc/client5/http/impl/win/WinHttpClients.java b/httpclient5-win/src/main/java/org/apache/hc/client5/http/impl/win/WinHttpClients.java
index 105005e..ef4fca2 100644
--- a/httpclient5-win/src/main/java/org/apache/hc/client5/http/impl/win/WinHttpClients.java
+++ b/httpclient5-win/src/main/java/org/apache/hc/client5/http/impl/win/WinHttpClients.java
@@ -37,8 +37,6 @@
import org.apache.hc.core5.http.config.Registry;
import org.apache.hc.core5.http.config.RegistryBuilder;
-import com.sun.jna.platform.win32.Sspi;
-
/**
* Factory methods for {@link org.apache.hc.client5.http.impl.classic.CloseableHttpClient} instances configured to use integrated
* Windows authentication by default.
@@ -54,14 +52,7 @@
public static boolean isWinAuthAvailable() {
String os = System.getProperty("os.name");
os = os != null ? os.toLowerCase(Locale.ROOT) : null;
- if (os != null && os.contains("windows")) {
- try {
- return Sspi.MAX_TOKEN_SIZE > 0;
- } catch (final Exception ignore) {
- // Likely ClassNotFound
- }
- }
- return false;
+ return os != null && os.contains("windows");
}
private static HttpClientBuilder createBuilder() {
diff --git a/httpclient5-win/src/main/java/org/apache/hc/client5/http/impl/win/WindowsNegotiateScheme.java b/httpclient5-win/src/main/java/org/apache/hc/client5/http/impl/win/WindowsNegotiateScheme.java
index 92c8f78..0daed7e 100644
--- a/httpclient5-win/src/main/java/org/apache/hc/client5/http/impl/win/WindowsNegotiateScheme.java
+++ b/httpclient5-win/src/main/java/org/apache/hc/client5/http/impl/win/WindowsNegotiateScheme.java
@@ -239,9 +239,6 @@
final RouteInfo route = clientContext.getHttpRoute();
if (route != null) {
spn = "HTTP/" + route.getProxyHost().getHostName();
- } else {
- // Should not happen
- spn = null;
}
} else {
final URIAuthority authority = request.getAuthority();
@@ -251,9 +248,6 @@
final RouteInfo route = clientContext.getHttpRoute();
if (route != null) {
spn = "HTTP/" + route.getTargetHost().getHostName();
- } else {
- // Should not happen
- spn = null;
}
}
}
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/NTLMEngineImpl.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/NTLMEngineImpl.java
index f784d34..d87ee94 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/NTLMEngineImpl.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/NTLMEngineImpl.java
@@ -687,9 +687,6 @@
* the NTLM Response and the NTLMv2 and LMv2 Hashes.
*/
private static byte[] ntlmHash(final char[] password) throws NTLMEngineException {
- if (UNICODE_LITTLE_UNMARKED == null) {
- throw new NTLMEngineException("Unicode not supported");
- }
final byte[] unicodePassword = new ByteArrayBuilder()
.charset(UNICODE_LITTLE_UNMARKED).append(password).toByteArray();
final MD4 md4 = new MD4();
@@ -705,9 +702,6 @@
*/
private static byte[] lmv2Hash(final String domain, final String user, final byte[] ntlmHash)
throws NTLMEngineException {
- if (UNICODE_LITTLE_UNMARKED == null) {
- throw new NTLMEngineException("Unicode not supported");
- }
final HMACMD5 hmacMD5 = new HMACMD5(ntlmHash);
// Upper case username, upper case domain!
hmacMD5.update(user.toUpperCase(Locale.ROOT).getBytes(UNICODE_LITTLE_UNMARKED));
@@ -725,9 +719,6 @@
*/
private static byte[] ntlmv2Hash(final String domain, final String user, final byte[] ntlmHash)
throws NTLMEngineException {
- if (UNICODE_LITTLE_UNMARKED == null) {
- throw new NTLMEngineException("Unicode not supported");
- }
final HMACMD5 hmacMD5 = new HMACMD5(ntlmHash);
// Upper case username, mixed case target!!
hmacMD5.update(user.toUpperCase(Locale.ROOT).getBytes(UNICODE_LITTLE_UNMARKED));
@@ -1071,9 +1062,6 @@
if ((flags & FLAG_REQUEST_UNICODE_ENCODING) == 0) {
return DEFAULT_CHARSET;
}
- if (UNICODE_LITTLE_UNMARKED == null) {
- throw new NTLMEngineException( "Unicode not supported" );
- }
return UNICODE_LITTLE_UNMARKED;
}
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/ContentTypeMatcher.java b/httpclient5/src/test/java/org/apache/hc/client5/http/ContentTypeMatcher.java
index 48a0b44..9ae9c1a 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/ContentTypeMatcher.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/ContentTypeMatcher.java
@@ -44,9 +44,7 @@
public boolean matches(final Object item) {
if (item instanceof ContentType) {
final ContentType contentType = (ContentType) item;
- if (contentType.isSameMimeType(expectedContentType)) {
- return true;
- }
+ return contentType.isSameMimeType(expectedContentType);
}
return false;
}
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/HeaderMatcher.java b/httpclient5/src/test/java/org/apache/hc/client5/http/HeaderMatcher.java
index 487eb15..721856a 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/HeaderMatcher.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/HeaderMatcher.java
@@ -47,9 +47,7 @@
public boolean matches(final Object item) {
if (item instanceof Header) {
final Header header = (Header) item;
- if (headerName.equalsIgnoreCase(header.getName()) && LangUtils.equals(headerValue, header.getValue())) {
- return true;
- }
+ return headerName.equalsIgnoreCase(header.getName()) && LangUtils.equals(headerValue, header.getValue());
}
return false;
}
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/NameValuePairsMatcher.java b/httpclient5/src/test/java/org/apache/hc/client5/http/NameValuePairsMatcher.java
index e63809a..87ce530 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/NameValuePairsMatcher.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/NameValuePairsMatcher.java
@@ -50,23 +50,21 @@
public boolean matches(final Object item) {
if (item instanceof Collection<?>) {
final Collection<?> collection = (Collection<?>) item;
- if (collection.size() == collection.size()) {
- int i = 0;
- for (final Object obj : collection) {
- if (obj instanceof NameValuePair) {
- final NameValuePair nvp1 = (NameValuePair) obj;
- final NameValuePair nvp2 = expectedNameValuePairList.get(i);
- if (!nvp1.getName().equalsIgnoreCase(nvp2.getName())
- || !LangUtils.equals(nvp1.getValue(), nvp2.getValue())) {
- return false;
- }
- } else {
+ int i = 0;
+ for (final Object obj : collection) {
+ if (obj instanceof NameValuePair) {
+ final NameValuePair nvp1 = (NameValuePair) obj;
+ final NameValuePair nvp2 = expectedNameValuePairList.get(i);
+ if (!nvp1.getName().equalsIgnoreCase(nvp2.getName())
+ || !LangUtils.equals(nvp1.getValue(), nvp2.getValue())) {
return false;
}
- i++;
+ } else {
+ return false;
}
- return true;
+ i++;
}
+ return true;
}
return false;
}