Skip to content

Commit 2a8eb16

Browse files
authored
fix: [FFM-12715]: Fixing null pointer in retry interceptor (#213)
* fix: [FFM-12715]: Fixing null pointer in retry interceptor * minor revert * minor revert 2
1 parent 29e0482 commit 2a8eb16

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-9.1.0-all.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.0-all.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ dependencyResolutionManagement {
44
versionCatalogs {
55
libs {
66
// main sdk version
7-
version('sdk', '1.9.0');
7+
version('sdk', '1.9.1');
88

99
// sdk deps
1010
version('okhttp3', '4.12.0')

src/main/java/io/harness/cf/client/connector/NewRetryInterceptor.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public Response intercept(@NotNull Chain chain) throws IOException {
7070
String.format(
7171
Locale.getDefault(), "httpCode=%d %s", response.code(), response.message());
7272
if (!shouldRetryHttpErrorCode(response.code())) {
73-
return response;
73+
return getReturnResp(chain, response, "nullcheck: shouldRetryHttpErrorCode is false");
7474
}
7575
} else if (tryCount > 1) {
7676
log.info(
@@ -83,7 +83,7 @@ public Response intercept(@NotNull Chain chain) throws IOException {
8383
response = makeErrorResp(chain, msg);
8484
successful = false;
8585
if (!shouldRetryException(ex)) {
86-
return response;
86+
return getReturnResp(chain, response, "nullcheck: shouldRetryException is false");
8787
}
8888
}
8989

@@ -110,7 +110,8 @@ public Response intercept(@NotNull Chain chain) throws IOException {
110110
tryCount,
111111
chain.request().url(),
112112
msg);
113-
return response; // Exit without further retries
113+
return getReturnResp(
114+
chain, response, "nullcheck: isShuttingDown is true"); // Exit without further retries
114115
}
115116

116117
log.warn(
@@ -134,7 +135,21 @@ public Response intercept(@NotNull Chain chain) throws IOException {
134135
tryCount++;
135136
} while (!successful && (retryForever || tryCount <= maxTryCount) && !isShuttingDown.get());
136137

137-
return response;
138+
return getReturnResp(
139+
chain,
140+
response,
141+
String.format(
142+
"nullcheck: exit loop successful=%s, retryForever=%s tryCount=%d maxTryCount=%d shutdown=%s",
143+
successful, retryForever, tryCount, maxTryCount, isShuttingDown.get()));
144+
}
145+
146+
// interceptor should never return null, create dummy resp and embed an error msg if it does
147+
private Response getReturnResp(Chain chain, Response resp, String msg) {
148+
if (resp != null) {
149+
return resp;
150+
}
151+
152+
return makeErrorResp(chain, String.format(msg, "%s url: %s", chain.request().url()));
138153
}
139154

140155
int getRetryAfterHeaderInSeconds(Response response) {

0 commit comments

Comments
 (0)