Skip to content

Commit

Permalink
Upgraded HC StyleCheck to version 3; fixed style-check violations (no…
Browse files Browse the repository at this point in the history
… functional changes)
  • Loading branch information
ok2c committed Sep 27, 2024
1 parent e9560a4 commit 007a5f6
Show file tree
Hide file tree
Showing 125 changed files with 619 additions and 612 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ protected HttpCacheContext createContext() {

@Override
public HttpCacheContext build() {
final HttpCacheContext context = super.build();
final HttpCacheContext context = super.build();
context.setRequestCacheControl(cacheControl);
return context;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ public class HeaderConstants {
public static final String CACHE_CONTROL_STALE_WHILE_REVALIDATE = "stale-while-revalidate";
public static final String CACHE_CONTROL_ONLY_IF_CACHED = "only-if-cached";
public static final String CACHE_CONTROL_MUST_UNDERSTAND = "must-understand";
public static final String CACHE_CONTROL_IMMUTABLE= "immutable";
public static final String CACHE_CONTROL_IMMUTABLE = "immutable";

/**
* @deprecated Use {@link #CACHE_CONTROL_STALE_IF_ERROR}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ private void handleCacheHit(
final AsyncExecChain.Scope scope,
final AsyncExecChain chain,
final AsyncExecCallback asyncExecCallback) {
final HttpCacheContext context = HttpCacheContext.cast(scope.clientContext);
final HttpCacheContext context = HttpCacheContext.cast(scope.clientContext);
final String exchangeId = scope.exchangeId;

if (LOG.isDebugEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public int getMaxCacheEntries() {
/**
* Returns the number of times to retry a cache processChallenge on failure
*/
public int getMaxUpdateRetries(){
public int getMaxUpdateRetries() {
return maxUpdateRetries;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public CacheSuitability assessSuitability(final RequestCacheControl requestCache

boolean requestMethodMatch(final HttpRequest request, final HttpCacheEntry entry) {
return request.getMethod().equalsIgnoreCase(entry.getRequestMethod()) ||
(Method.HEAD.isSame(request.getMethod()) && Method.GET.isSame(entry.getRequestMethod()));
Method.HEAD.isSame(request.getMethod()) && Method.GET.isSame(entry.getRequestMethod());
}

boolean requestUriMatch(final HttpRequest request, final HttpCacheEntry entry) {
Expand Down Expand Up @@ -295,10 +295,10 @@ public boolean allConditionalsMatch(final HttpRequest request, final HttpCacheEn
return true;
}

final boolean etagValidatorMatches = (hasEtagValidator) && etagValidatorMatches(request, entry);
final boolean lastModifiedValidatorMatches = (hasLastModifiedValidator) && lastModifiedValidatorMatches(request, entry, now);
final boolean etagValidatorMatches = hasEtagValidator && etagValidatorMatches(request, entry);
final boolean lastModifiedValidatorMatches = hasLastModifiedValidator && lastModifiedValidatorMatches(request, entry, now);

if ((hasEtagValidator && hasLastModifiedValidator)
if (hasEtagValidator && hasLastModifiedValidator
&& !(etagValidatorMatches && lastModifiedValidatorMatches)) {
return false;
} else if (hasEtagValidator && !etagValidatorMatches) {
Expand All @@ -309,9 +309,9 @@ public boolean allConditionalsMatch(final HttpRequest request, final HttpCacheEn
}

boolean hasUnsupportedConditionalHeaders(final HttpRequest request) {
return (request.containsHeader(HttpHeaders.IF_RANGE)
return request.containsHeader(HttpHeaders.IF_RANGE)
|| request.containsHeader(HttpHeaders.IF_MATCH)
|| request.containsHeader(HttpHeaders.IF_UNMODIFIED_SINCE));
|| request.containsHeader(HttpHeaders.IF_UNMODIFIED_SINCE);
}

boolean hasSupportedEtagValidator(final HttpRequest request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ ClassicHttpResponse callBackend(
final HttpHost target,
final ClassicHttpRequest request,
final ExecChain.Scope scope,
final ExecChain chain) throws IOException, HttpException {
final ExecChain chain) throws IOException, HttpException {

final String exchangeId = scope.exchangeId;
final Instant requestDate = getCurrentDate();
Expand All @@ -244,7 +244,7 @@ private ClassicHttpResponse handleCacheHit(
final ExecChain.Scope scope,
final ExecChain chain) throws IOException, HttpException {
final String exchangeId = scope.exchangeId;
final HttpCacheContext context = HttpCacheContext.cast(scope.clientContext);
final HttpCacheContext context = HttpCacheContext.cast(scope.clientContext);

if (LOG.isDebugEnabled()) {
LOG.debug("{} cache hit: {}", exchangeId, new RequestLine(request));
Expand Down Expand Up @@ -353,7 +353,7 @@ ClassicHttpResponse revalidateCacheEntry(
final ClassicHttpRequest request,
final ExecChain.Scope scope,
final ExecChain chain) throws IOException, HttpException {
final HttpCacheContext context = HttpCacheContext.cast(scope.clientContext);
final HttpCacheContext context = HttpCacheContext.cast(scope.clientContext);
Instant requestDate = getCurrentDate();
final ClassicHttpRequest conditionalRequest = conditionalRequestBuilder.buildConditionalRequest(
responseCacheControl, request, hit.entry);
Expand Down Expand Up @@ -397,7 +397,7 @@ ClassicHttpResponse revalidateCacheEntryWithoutFallback(
final ExecChain.Scope scope,
final ExecChain chain) throws HttpException {
final String exchangeId = scope.exchangeId;
final HttpCacheContext context = HttpCacheContext.cast(scope.clientContext);
final HttpCacheContext context = HttpCacheContext.cast(scope.clientContext);
try {
return revalidateCacheEntry(responseCacheControl, hit, target, request, scope, chain);
} catch (final IOException ex) {
Expand All @@ -418,7 +418,7 @@ ClassicHttpResponse revalidateCacheEntryWithFallback(
final ExecChain.Scope scope,
final ExecChain chain) throws HttpException, IOException {
final String exchangeId = scope.exchangeId;
final HttpCacheContext context = HttpCacheContext.cast(scope.clientContext);
final HttpCacheContext context = HttpCacheContext.cast(scope.clientContext);
final ClassicHttpResponse response;
try {
response = revalidateCacheEntry(responseCacheControl, hit, target, request, scope, chain);
Expand Down Expand Up @@ -490,7 +490,7 @@ ClassicHttpResponse cacheAndReturnResponse(
final Instant requestSent,
final Instant responseReceived) throws IOException {
final String exchangeId = scope.exchangeId;
final HttpCacheContext context = HttpCacheContext.cast(scope.clientContext);
final HttpCacheContext context = HttpCacheContext.cast(scope.clientContext);
final int statusCode = backendResponse.getCode();
// handle 304 Not Modified responses
if (statusCode == HttpStatus.SC_NOT_MODIFIED) {
Expand Down Expand Up @@ -573,7 +573,7 @@ private ClassicHttpResponse handleCacheMiss(
}
cacheMisses.getAndIncrement();

final HttpCacheContext context = HttpCacheContext.cast(scope.clientContext);
final HttpCacheContext context = HttpCacheContext.cast(scope.clientContext);
if (requestCacheControl.isOnlyIfCached()) {
if (LOG.isDebugEnabled()) {
LOG.debug("{} request marked only-if-cached", exchangeId);
Expand Down Expand Up @@ -643,7 +643,7 @@ ClassicHttpResponse negotiateResponseFromVariants(
return callBackend(target, unconditional, scope, chain);
}

final HttpCacheContext context = HttpCacheContext.cast(scope.clientContext);
final HttpCacheContext context = HttpCacheContext.cast(scope.clientContext);
context.setCacheResponseStatus(CacheResponseStatus.VALIDATED);
cacheUpdates.getAndIncrement();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ public boolean isActive() {
return active.get();
}

private boolean compareAndSet(){
private boolean compareAndSet() {
return this.active.compareAndSet(true, false);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ protected boolean isExplicitlyNonCacheable(final ResponseCacheControl cacheContr
// The response is considered explicitly non-cacheable if it contains
// "no-store" or (if sharedCache is true) "private" directives.
// Note that "no-cache" is considered cacheable but requires validation before use.
return cacheControl.isNoStore() || (sharedCache && cacheControl.isCachePrivate());
return cacheControl.isNoStore() || sharedCache && cacheControl.isCachePrivate();
}

protected boolean isExplicitlyCacheable(final ResponseCacheControl cacheControl, final HttpResponse response) {
Expand Down Expand Up @@ -371,11 +371,11 @@ private Duration calculateFreshnessLifetime(final ResponseCacheControl cacheCont
* @return true if the HTTP status code is understood, false otherwise.
*/
private boolean understoodStatusCode(final int status) {
return (status >= 200 && status <= 206) ||
(status >= 300 && status <= 399) ||
(status >= 400 && status <= 417) ||
(status == 421) ||
(status >= 500 && status <= 505);
return status >= 200 && status <= 206 ||
status >= 300 && status <= 399 ||
status >= 400 && status <= 417 ||
status == 421 ||
status >= 500 && status <= 505;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ void canGetOriginalHeaders() {
entry = makeEntry(Instant.now(), Instant.now(), HttpStatus.SC_OK, headers, mockResource, null);
final Header[] result = entry.getHeaders();
assertEquals(headers.length, result.length);
for(int i=0; i<headers.length; i++) {
for (int i = 0; i < headers.length; i++) {
assertEquals(headers[i], result[i]);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static boolean equivalent(final HttpEntity e1, final HttpEntity e2) throw
return false;
}
}
return (-1 == i2.read());
return -1 == i2.read();
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public static byte[] serialize(final String key, final HttpCacheEntry value) thr

@BeforeEach
@SuppressWarnings("unchecked")
public void setUp() {
void setUp() {
MockitoAnnotations.openMocks(this);
impl = Mockito.mock(AbstractBinaryAsyncCacheStorage.class,
Mockito.withSettings().defaultAnswer(Answers.CALLS_REAL_METHODS).useConstructor(3));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static byte[] serialize(final String key, final HttpCacheEntry value) thr

@BeforeEach
@SuppressWarnings("unchecked")
public void setUp() {
void setUp() {
impl = Mockito.mock(AbstractBinaryCacheStorage.class,
Mockito.withSettings().defaultAnswer(Answers.CALLS_REAL_METHODS).useConstructor(3));
}
Expand Down Expand Up @@ -125,7 +125,7 @@ void testCacheGetKeyMismatch() throws Exception {
}

@Test
void testCacheRemove() throws Exception{
void testCacheRemove() throws Exception {
final String key = "foo";

when(impl.digestToStorageKey(key)).thenReturn("bar");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void testApparentAgeIsResponseReceivedTimeLessDateHeader() {
@Test
void testNegativeApparentAgeIsBroughtUpToZero() {
final Header[] headers = new Header[] { new BasicHeader("Date", DateUtils.formatStandardDate(sixSecondsAgo)) };
final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(now, tenSecondsAgo, headers);
final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(now, tenSecondsAgo, headers);
assertEquals(TimeValue.ofSeconds(0), impl.getApparentAge(entry));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,36 +399,36 @@ void testSimpleVariantMap() throws Exception {
*/
@Test
void testDeserializeCacheEntryWithTrailingGarbage() {
final String content1 =HttpByteArrayCacheEntrySerializer.HC_CACHE_VERSION_LINE + "\n" +
final String content1 = HttpByteArrayCacheEntrySerializer.HC_CACHE_VERSION_LINE + "\n" +
"HC-Key: unique-cache-key\n" +
"HC-Resource-Length: 11\n" +
"HC-Request-Instant: 1686210849596\n" +
"HC-Response-Instant: 1686210849596\n" +
"\n" +
"GET /stuff HTTP/1.1\n" +
"\n" +
"HTTP/1.1 200 \n" +
"Content-Type: text/plain; charset=UTF-8\n" +
"Cache-control: public, max-age=31536000\n" +
"\n" +
"Hello World..... Rubbish";
"HC-Resource-Length: 11\n" +
"HC-Request-Instant: 1686210849596\n" +
"HC-Response-Instant: 1686210849596\n" +
"\n" +
"GET /stuff HTTP/1.1\n" +
"\n" +
"HTTP/1.1 200 \n" +
"Content-Type: text/plain; charset=UTF-8\n" +
"Cache-control: public, max-age=31536000\n" +
"\n" +
"Hello World..... Rubbish";
final byte[] bytes1 = content1.getBytes(StandardCharsets.UTF_8);
final ResourceIOException exception1 = Assertions.assertThrows(ResourceIOException.class, () ->
httpCacheEntrySerializer.deserialize(bytes1));
Assertions.assertEquals("Unexpected content at the end of cache content", exception1.getMessage());

final String content2 =HttpByteArrayCacheEntrySerializer.HC_CACHE_VERSION_LINE + "\n" +
final String content2 = HttpByteArrayCacheEntrySerializer.HC_CACHE_VERSION_LINE + "\n" +
"HC-Key: unique-cache-key\n" +
"HC-Request-Instant: 1686210849596\n" +
"HC-Response-Instant: 1686210849596\n" +
"\n" +
"GET /stuff HTTP/1.1\n" +
"\n" +
"HTTP/1.1 200 \n" +
"Content-Type: text/plain; charset=UTF-8\n" +
"Cache-control: public, max-age=31536000\n" +
"\n" +
"Rubbish";
"HC-Request-Instant: 1686210849596\n" +
"HC-Response-Instant: 1686210849596\n" +
"\n" +
"GET /stuff HTTP/1.1\n" +
"\n" +
"HTTP/1.1 200 \n" +
"Content-Type: text/plain; charset=UTF-8\n" +
"Cache-control: public, max-age=31536000\n" +
"\n" +
"Rubbish";
final byte[] bytes2 = content2.getBytes(StandardCharsets.UTF_8);
final ResourceIOException exception2 = Assertions.assertThrows(ResourceIOException.class, () ->
httpCacheEntrySerializer.deserialize(bytes2));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ private void testDoesNotReturnStaleResponseOnError(final ClassicHttpRequest req2
ClassicHttpResponse result = null;
try {
result = execute(req2);
} catch (final IOException acceptable) {
} catch (final IOException expected) {
}

if (result != null) {
Expand Down Expand Up @@ -745,8 +745,8 @@ void testSendsAllVariantEtagsInConditionalRequest() throws Exception {
final ClassicHttpRequest captured = reqCapture.getValue();
boolean foundEtag1 = false;
boolean foundEtag2 = false;
for(final Header h : captured.getHeaders("If-None-Match")) {
for(final String etag : h.getValue().split(",")) {
for (final Header h : captured.getHeaders("If-None-Match")) {
for (final String etag : h.getValue().split(",")) {
if ("\"etag1\"".equals(etag.trim())) {
foundEtag1 = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1212,7 +1212,7 @@ void testCachedEntityBodyIsUsedForResponseAfter304Validation() throws Exception
try (final InputStream i1 = resp1.getEntity().getContent();
final InputStream i2 = result.getEntity().getContent()) {
int b1, b2;
while((b1 = i1.read()) != -1) {
while ((b1 = i1.read()) != -1) {
b2 = i2.read();
Assertions.assertEquals(b1, b2);
}
Expand Down Expand Up @@ -1262,7 +1262,7 @@ void testResponseIncludesCacheEntryEndToEndHeadersForResponseAfter304Validation(
"Content-MD5", "Content-Type", "Expires", "Last-Modified",
"Location", "Retry-After"
};
for(final String h : endToEndHeaders) {
for (final String h : endToEndHeaders) {
Assertions.assertEquals(HttpTestUtils.getCanonicalHeaderValue(resp1, h),
HttpTestUtils.getCanonicalHeaderValue(result, h));
}
Expand Down Expand Up @@ -1306,7 +1306,7 @@ void testUpdatedEndToEndHeadersFrom304ArePassedOnResponseAndUpdatedInCacheEntry(
"Content-Location", "Content-Type", "Expires", "Location",
"Retry-After"
};
for(final String h : endToEndHeaders) {
for (final String h : endToEndHeaders) {
Assertions.assertEquals(HttpTestUtils.getCanonicalHeaderValue(resp2, h),
HttpTestUtils.getCanonicalHeaderValue(result1, h));
Assertions.assertEquals(HttpTestUtils.getCanonicalHeaderValue(resp2, h),
Expand Down Expand Up @@ -2093,7 +2093,7 @@ void testOrderOfMultipleContentEncodingHeaderValuesIsPreserved() throws Exceptio
final Iterator<HeaderElement> it = MessageSupport.iterate(result, HttpHeaders.CONTENT_ENCODING);
while (it.hasNext()) {
final HeaderElement elt = it.next();
switch(total_encodings) {
switch (total_encodings) {
case 0:
Assertions.assertEquals("gzip", elt.getName());
break;
Expand All @@ -2118,7 +2118,7 @@ void testOrderOfMultipleParametersInContentEncodingHeaderIsPreserved() throws Ex
final Iterator<HeaderElement> it = MessageSupport.iterate(result, HttpHeaders.CONTENT_ENCODING);
while (it.hasNext()) {
final HeaderElement elt = it.next();
switch(total_encodings) {
switch (total_encodings) {
case 0:
Assertions.assertEquals("gzip", elt.getName());
break;
Expand Down
Loading

0 comments on commit 007a5f6

Please sign in to comment.